How to resolve undefined symbols like functions defined inside another library

3 weeks ago 34
ARTICLE AD BOX

Why does nm shows U printa in libb.so even though liba.so is linked?

This is a normal and expected behaviour when working with shared libraries (.so) on ELF-based systems.

In your setup:

liba.so defines the function printa

libb.so calls printa and links against liba.so

Because printa is not defined inside libb.so itself, nm correctly reports it as an undefined symbol (U)

Why does this still works?

When building a shared library, the linker does not copy function code from other .so files. Instead, it records a runtime dependency

At runtime, the dynamic loader loads liba.so and resolves printa automatically

You can verify the dependency:

ldd libd.so

Is this an error?

No. This is correct and intended design for shared libraries on linux.

When is it a problem?

Only if the program fails at runtime with:

undefined symbol: printa

Is it possible to make U change to T?

Only by static linking liba into libb(copying the code), which is not recommended for shared libraries

Read Entire Article