   Falsely reported missing symbols in my library
  Hello. My code has essentially this structure:X.hppclass {  public: X ();};X.cppX :: X () {  // ...}Y.hppclass Y {  public: Y ();};extern "C" {  void foo ();}Y.cppY :: Y () {  X x;}void foo () {  Y y;}I compile these withQuote:g++ -c X.cpp -o X.og++ -c -fPIC Y.cpp -o Y.og++ -shared X.o Y.o -o Y.soIn another program I explicitly at runtime load the library Y symbol "foo" and call it, which of course creates a Y object which in turn creates an X object.The program aborts, printing this error:Quote:symbol lookup error: /path/to/Y.so: undefined symbol: _ZN1XC1EvI gather from investigating name-mangling that this means the constructor for X is not known. However, the string "_ZN1XC1Ev" is definitely exported, I can see it in the string table. A further sanity check, omitting X.o from the g++ command which generates Y.so results in a smaller output file (In my real project, both these classes are much larger and the difference is substantial, not a rounding error).Can someone please explain to me why code in the shared object Y hasn't implicitly linked to the code in the static object X?(I'm loading it with the Qt QLibrary class, so if there's a low-level function I need to call to bind this code to itself I'm definitely not doing it. I expect there is an omission in my linker arguments, or is this all crazy?)Thanks for reading.   
  Have you tried changing the order of object files:g++ -shared Y.o X.o -o Y.so Since X is used in Y, X.o should appear after Y.o . (link)Also, I think you need to compile all files with -fPIC option and also pass it to the linker.   ;  Thanks that fixed it   