Reputation: 3411
I'm using gcc. 4.4.7. If I mark a function as hidden in module A.h:
//module A.h
__attribute__ ((visibility ("hidden"))) void foo() { ... }
I can obviously still call foo from within module A.h. If I have a second module B.h that references A::foo:
//module B.h
#include "A.h"
foo();
Why isn't an error thrown? If A::foo is technically undefined in module B?
edit removed "nothing happens when foo is called in module B". had some code set up wrong
edit2 I'm looking at this tutorial for setting up local references in a header file so that they can't be called from other modules. Maybe I'm missing something?
edit3 I am compling with -fvisibility=hidden
Upvotes: 0
Views: 97
Reputation: 45674
visibility ("visibility_type")
This attribute affects the linkage of the declaration to which it is attached. There are four supported visibility_type values: default, hidden, protected or internal visibility.
[...]
hidden
Hidden visibility indicates that the entity declared has a new form of linkage, which we call “hidden linkage”. Two declarations of an object with hidden linkage refer to the same object if they are in the same shared object.
Two compilation units which are linked together are in the same shared object.
Upvotes: 3
Reputation: 357
Are you compiling this code with the -fvisibility=hidden flag? If so, then try
#pragma GCC visibility push(hidden)
Upvotes: 0