码迷,mamicode.com
首页 > 其他好文 > 详细

__attribute__ ((default)) 和 __attribute__ ((hidden))

时间:2016-04-16 16:49:35      阅读:552      评论:0      收藏:0      [点我收藏+]

标签:

制作一个共享库

1 /* a.h */
2 int func();
1 /* a.c */
2 #include <stdio.h>
3 #include "a.h"
4 
5 int func()
6 {
7     printf("### func ###\n");
8     return 0;
9 }
gcc -shared -o liba.so a.c -fPIC


main.c

1 #include "a.h"
2 
3 int main()
4 {
5     func();
6     return 0
7 }
gcc -o main main.c -la -L. -Wl,-rpath=.

 

如果在 func 前面加上

__attribute__((visibility("hidden")))

在编译 main 时,报错:

/tmp/ccbxiXwp.o: In function `main:
main.c:(.text+0x7): undefined reference to `funccollect2: error: ld returned 1 exit status


如果在编译动态库时加上 -fvisibility=hidden,表示动态库的符号都是 hidden的

在函数前加上 __attribute__((visibility("default"))) 可以使函数对外可见

 

__attribute__ ((default)) 和 __attribute__ ((hidden))

标签:

原文地址:http://www.cnblogs.com/jingyg/p/5398653.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!