Gcc hides the visibility of symbols coming from an included static library
I have:
- a shared library, say libShared.so, which contains a class
Bar
using the methodint Bar::do(int d) const
- a static library, say libStatic.a, which contains a class
Foo
with a methodint Foo::act(int a) const
.
The code Bar
looks 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 the -fvisibility = hidden flag.
The problem is this: I run the Linux command nm -g -D -C --defined-only libShared.so and this makes the Foo class along with its method visible outside libShared.so, even though it told the compiler to hide everything except what is marked as "public" (infact, they are marked as "T" on nm).
How can I avoid this? I want libShared.so to not display symbols coming from its dependencies.
thank
+3
source to share