×
嵌入式 > 嵌入式开发 > 详情

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

发布时间:2024-03-11 发布时间:
|
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 DLLs 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")))的函数才是对外可见的。



『本文转载自网络,版权归原作者所有,如有侵权请联系删除』

热门文章 更多
RIOS实验室联手Imagination.共同助力RISC-V生态发展