简体   繁体   English

为什么在使用-fvisibility = hidden时仍导出构造函数

[英]Why constructor still be exported when I using -fvisibility=hidden

I have a class A: 我有A班:

class A
{
public:
   A() {}
   virtual ~A() {}

   void Func();
};

and another class M using A. I want to create libM.so which hidden all A's symbols. 和另一个使用A的类M。我想创建libM.so,它隐藏了所有A的符号。 I using the following script to compile it: 我使用以下脚本进行编译:

g++ -c A.cc -fPIC -fvisibility=hidden
g++ -c M.cc -fPIC
g++ -shared -z defs -o libM.so M.o A.o

But when I using "nm -DC libM.so", it still has 但是当我使用“ nm -DC libM.so”时,它仍然具有

0000000000000c78 W A::A()
0000000000000c78 W A::A()

I search this question on google and found another gcc option: "-fvisibility-inlines-hidden" to hidden inline functions, but I still got the same result even add this option when compile Ao 我在Google上搜索了此问题,发现了另一个gcc选项:“-fvisibility-inlines-hidden”到隐藏的内联函数,但是即使在编译Ao时添加此选项,我仍然得到相同的结果

g++ -c A.cc -fPIC -fvisibility=hidden -fvisibility-inlines-hidden

Why "-fvisibility-inlines-hidden" doesn't have effect? 为什么“ -fvisibility-inlines-hidden”不起作用? How do I prevent A::A() to appear in libM.so's export symbol? 如何防止A :: A()出现在libM.so的导出符号中? Thank you very much! 非常感谢你!

Thanks to Mike Seymour. 感谢Mike Seymour。 I should add -fvisibility-inlines-hidden when I compile M.cc 编译M.cc时,我应该添加-fvisibility-inlines-hidden

g++ -c A.cc -fPIC -fvisibility=hidden -fvisibility-inlines-hidden
g++ -c M.cc -fPIC -fvisibility-inlines-hidden
g++ -shared -z defs -o libM.so M.o A.o

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 为什么`-fvisibility-inlines-hidden`不是默认值? - Why `-fvisibility-inlines-hidden` is not the default? 在 Linux 中使用 -fvisibility=hidden 编译时库加载错误 - Library load error when compiled with -fvisibility=hidden in Linux 使用clang ++,-fvisibility = hidden,typeinfo和type-erasure - Using clang++, -fvisibility=hidden, and typeinfo, and type-erasure C ++ -fvisibility = hidden -fvisibility-inlines-hidden - C++ -fvisibility=hidden -fvisibility-inlines-hidden -fvisibility-inlines-hidden 与 gcc 中的 -fvisibility=hidden 有何不同 - How -fvisibility-inlines-hidden differs from -fvisibility=hidden in gcc -fvisibility=hidden 编译器未通过调试构建传递 - -fvisibility=hidden not passed by compiler for Debug builds 我继承了一个使用private的构造函数,为什么我仍然可以从main函数访问它? - I Inherited a constructor using private, Why am I still be able to access it from main function? Phyon在Cygwin上抱怨Qt编译时不支持-fvisibility = hidden - Phonon on Cygwin complains about Qt compiled without support for -fvisibility=hidden 为什么仍将隐藏符号添加到DSO - Why hidden symbols are still added to DSO 为什么在使用SDL2时仍然出现“未定义参考”链接器错误? - Why am I still getting 'undefined reference' linker errors when using SDL2?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM