4

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!

cgspwei
  • 63
  • 5
  • 4
    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 Jan 30 '13 at 04:32
  • Thank you very much! Yes, it is right. I should add -fvisibility-inlines-hidden when I compile M.cc. – cgspwei Jan 30 '13 at 04:39
  • Please answer your own question with what you've found out and accept it to close this issue. – vonbrand Jan 30 '13 at 12:09

1 Answers1

1

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
cgspwei
  • 63
  • 5
  • But I tried, and found that `-fvisibility-inlines-hidden` cannot hide A's symbol. Instead, only use `-fvisibility=hidden` for the first two line will remove A's symbol in libM.so. I'm using gcc 5.4.0 – flm8620 Dec 24 '19 at 13:41