为什么在使用-fvisibility = hidden时仍导出构造函数 [英] Why constructor still be exported when I using -fvisibility=hidden
问题描述
我有A类:
class A
{
public:
A() {}
virtual ~A() {}
void Func();
};
和另一个使用A的类M.我想创建libM.so,它隐藏了所有A的符号. 我使用以下脚本对其进行编译:
and another class M using A. I want to create libM.so which hidden all A's symbols. 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
但是当我使用"nm -DC libM.so"时,它仍然具有
But when I using "nm -DC libM.so", it still has
0000000000000c78 W A::A()
0000000000000c78 W A::A()
我在Google上搜索了此问题,并找到了另一个gcc选项:-fvisibility-inlines-hidden"到隐藏的内联函数,但是即使在编译A.o时添加此选项,我仍然得到相同的结果
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 A.o
g++ -c A.cc -fPIC -fvisibility=hidden -fvisibility-inlines-hidden
为什么"-fvisibility-inlines-hidden"无效?如何防止A :: A()出现在libM.so的导出符号中?非常感谢你!
Why "-fvisibility-inlines-hidden" doesn't have effect? How do I prevent A::A() to appear in libM.so's export symbol? Thank you very much!
推荐答案
感谢Mike Seymour.编译M.cc时,我应该添加-fvisibility-inlines-hidden
Thanks to Mike Seymour. I should add -fvisibility-inlines-hidden when I compile M.cc
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
这篇关于为什么在使用-fvisibility = hidden时仍导出构造函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!