I have:
Bar
, with a method int Bar::do(int d) const
Foo
, with a method int Foo::act(int a) const
. The code of Bar
is something like this:
//Bar.h
class __attribute__ ((visibility ("default"))) Bar
{
private:
__attribute__ ((visibility ("hidden"))) int privateMethod(int x) const;
public:
Bar() {}
int do(int d) const;
}
//Bar.cpp
#include "Bar.h"
#include "Foo.h"
int Bar::do(int d) const {
Foo foo;
int result = foo.act(d) + this->privateMethod(d);
return result;
}
libShared.so is compiled with flag -fvisibility=hidden.
The problem is the following: I execute Linux command nm -g -D -C --defined-only libShared.so, and it results that class Foo, along with its method, is visible outside libShared.so, despite having told to the compiler to hide everything except what is marked as "public" (infact, they are marked as "T" by nm).
How can I avoid this? I want libShared.so not to expose symbols coming from its dependencies.
Thanks
You need to compile libStatic.a also with flag -fvisibility=hidden
.
-fvisibility=hidden
only affects the default visibility of symbols generated by the compiler, it does not modify the visibility of existing symbols such as those obtained from static libraries.
Fortunately the linker does have a flag to do exactly that: Use -Wl,--exclude-libs=ALL
to change the visibility of global symbols from static libraries to "hidden", thus preventing them from being exported by your shared library.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With