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!

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

1 Answer 1

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
Sign up to request clarification or add additional context in comments.

1 Comment

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.