0

I'm experiencing a strange build issue on Linux and would like to know how this could happen, since it doesn't seem possible.

My project is a static library, 'libMyLib.a', and consists of a single source file, 'MyClass.cpp'. It's built with CMake and the gcc toolchain.

Using 'nm', I've determined that 'MyClass.cpp.o' contains the 'MyClass' symbol (i.e. it is "defined" as 'V' according to 'nm'). Using 'ar', I've determined that 'libMyLib.a' contains 'MyClass.cpp.o'.

But according to 'nm', the symbol 'MyClass' is "undefined" as 'U' within 'libMyLib.a'. How can it contain the object file, but the symbol within that object file is undefined?

Bungles
  • 1,969
  • 2
  • 25
  • 54
  • 2
    Just a note about terminology -- an .a file is not linked yet. It's literally just an archive of .o files. Linking is the very last build step, which resolves references to symbols (relocs) to their definitions from the .o/.a files it's given, and (for statically linked symbols) places those symbols at fixed addresses. – Cameron Apr 12 '18 at 18:33
  • Could you paste the results of the commands that you ran? – luantkow Apr 12 '18 at 19:30
  • This example is abstracted from a larger project, so I've simplified it for presentation. – Bungles Apr 12 '18 at 20:09

0 Answers0