WEB开发网
开发学院操作系统Linux/Unix 控制linux动态链接库导出函数 阅读

控制linux动态链接库导出函数

 2013-04-29 14:30:48 来源:开发学院   
核心提示:在linux中,我们可以通过-fvisibility=default|internal|hidden|protected来控制导出函数,控制linux动态链接库导出函数,在GCC帮助文档 -fvisibility=default|internal|hidden|protected参数下有这样一段描述:a superio

在linux中,我们可以通过-fvisibility=default|internal|hidden|protected来控制导出函数。

在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")))的函数才是对外可见的。

Tags:控制 linux 动态

编辑录入:爽爽 [复制链接] [打 印]
赞助商链接