Gcc hide visibility of symbols coming from included static library

I have:

  1. a shared library, say libShared.so, which contains a class Bar, with a method int Bar::do(int d) const
  2. a static library, say libStatic.a, which contains a class 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


Source: gcc

Leave a Reply