编译一个1.c文件:#include "stdio.h"#if defined(__GNUC__) && \ ((__GNUC__ >= 4) || (__GNUC__ == 3 && __GNUC_MINOR__ >= 3))#define NP_VISIBILITY_DEFAULT __attribute__((visibility("default")))#else#define NP_VISIBILITY_DEFAULT#endif#define NP_EXPORT(__type) NP_VISIBILITY_DEFAULT __typeNP_EXPORT(int) a(){printf("1.c i am a\0");return 0;}int b(){return 0;}我的目的是默认没有使用NP_EXPORT宏的函数都隐藏起来,即把b函数给隐藏起来,而a函数则导出去。我的编译步骤和指令如下:gcc -c 1.cgcc –fPIC -shared -fvisibility=hidden -o 1.so 1.o编译后生成了1.so文件。我使用nm工具查看,这个时候就可以达到隐藏不必要的函数,而只是导出定义过的函数。

评论