Chinaunix首页 | 论坛 | 博客
  • 博客访问: 357021
  • 博文数量: 132
  • 博客积分: 3066
  • 博客等级: 中校
  • 技术积分: 781
  • 用 户 组: 普通用户
  • 注册时间: 2009-04-14 16:19
文章分类

全部博文(132)

文章存档

2012年(1)

2010年(50)

2009年(81)

我的朋友

分类: C/C++

2010-06-11 14:19:48

编译一个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 __type

NP_EXPORT(int) a()
{
printf("1.c i am a\0");
return 0;
}
int b()
{
return 0;
}
我的目的是默认没有使用NP_EXPORT宏的函数都隐藏起来,即把b函数给隐藏起来,而a函数则导出去。

我的编译步骤和指令如下:
gcc -c 1.c
gcc –fPIC -shared -fvisibility=hidden  -o 1.so 1.o

编译后生成了1.so文件。
我使用nm工具查看,这个时候就可以达到隐藏不必要的函数,而只是导出定义过的函数。
 
阅读(754) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~