3
votes

I have a class 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. 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

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 A.o

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

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!

1
The inline constructor will be defined in both translation units, so presumably you need the compiler option for both, not just A.cc. (Not an answer since I don't have a computer available to test my guess at the moment) - Mike Seymour
Thank you very much! Yes, it is right. I should add -fvisibility-inlines-hidden when I compile M.cc. - cgspwei
Please answer your own question with what you've found out and accept it to close this issue. - vonbrand

1 Answers

0
votes

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