Continued from C++ shared library
Let’s see the symbols as reported by nm in liba.so and exec. Removing the extra symbols that are there for initialisation and all. Running nm -C <file>
a.cpp:
void f() {}
static void g() {}
void h();
void foo() { h(); }For a.o:
0000000000000000 T f()
U h()
000000000000000e T foo()
0000000000000007 t g()
For liba.so:
0000000000001109 T f()
U h()
0000000000001117 T foo()
0000000000001110 t g()
b.cpp:
void f();
void h() {}
int main() {
f();
}For exec:
0000000000001140 T main
U f()
0000000000001139 T h()
Observations in liba.so and `a.o:
- “T”: There are 2 strong symbols,
f()andfoo(). These are global symbols, and can be referenced by other modules being linked too. - “t”: There is a an internal symbol,
g(). This is a static function and won’t be visible to other modules - “U”: There is an undefined symbol
h(). This function has to be present in the final linking otherwise we’ll get an undefined symbol error.
Observations in exec:
- This has the strong symbol
h(). This function will be used by the shared library - Undefined symbol
f(), this is provided by the shared library.
NOTE: Since g() is static and unused, enabling optimisations in creating a.o removes the symbol g(). See C++ static function (a)