您的位置:首页 > 运维架构 > Linux

控制linux动态链接库(so, standard object)导出函数(转)

2010-11-18 19:58 357 查看
http://blog.csdn.net/wangjingfei/archive/2010/06/25/5693535.aspx
在windows中,我们可以指定__declspec(dllexport)定义来控制导出函数,在linux下,我们也有类似的控制参数。
在GCC帮助文档 -fvisibility=default|internal|hidden|protected参数下有这样一段描述:
a superior solution made possible by this option to marking things hidden when the default is public is to make the default hidden and mark things public. This is the norm with DLL's on Windows and with -fvisibility=hidden and "__attribute__ ((visibility("default")))" instead of "__declspec(dllexport)" you get almost identical semantics with identical syntax. This is a great boon to those working with cross-platform projects.
需要了解的是,在linux下,源文件中的所有函数都有一个默认的visibility属性为public,在编译命令中加入 -fvisibility=hidden参数,会将所有默认的public的属性变为hidden。此时,如果对函数设置__attribute__ ((visibility("default")))参数,使特定的函数仍然按默认的public属性处理,则-fvisibility=hidden参数不会对该函数起作用。所以,设置了-fvisibility=hidden参数之后,只有设置了__attribute__ ((visibility("default")))的函数才是对外可见的,如此则效果等同于Visual Studio下的__declspec(dllexport)定义。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: