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