ELF: linking: Why do I get undefined references in .so files

前端 未结 4 2022
刺人心
刺人心 2021-02-06 03:50

I\'m trying to build a program against wxWidgets, and I get a linker error. I\'d like to really understand what it means. The error is:

/usr/lib/libwx_baseu-2.8.         


        
相关标签:
4条回答
  • 2021-02-06 04:16

    I thought that .so files had all its symbols resolved, contrary to .o files that still need linking.

    Shared libraries can be incomplete, that is OK.

    do you know how I can get a list on undefined symbols in an ELF file

    Use

    nm -C -u libwx_baseu-2.8.so

    0 讨论(0)
  • 2021-02-06 04:16

    I think you don't link to some of the libraries when linking your program.

    You should link in your program to all shared libraries you link to in your .so

    If the .so is linked to some static libraries - it's not required in the program to link to them if all needed symbols are found in the .so

    You may use nm linux command to see the symbols in object file, library or binary

    Edit
    Your particular problem can be described here: http://old.nabble.com/-Bug-49433--gcc4.4,-NEW:-gcc4.4-misses-std::endl-implementation-at--O2%2B-td22836171.html

    0 讨论(0)
  • 2021-02-06 04:28

    When you link a shared library against other shared libraries (e.g. link libwx_baseu-2.8.so against libstdc++.so), the linker records versioned symbols used by libwx_baseu and provided by libstdc++.

    If at runtime you use a different copy of libstdc++ (one which doesn't provide the same versioned symbol(s)), you get a (dynamic) liking error and the program doesn't run at all (this is preferable to a "mystery" crash later on).

    But what's happening here is that you try to link an executable, which means the (static) linker wants to find all symbols which will be required at runtime. Again, you are linking the executable against a different (older) libstdc++.so, and so the linking fails.

    There are two usual root causes:
    - either you linked libwx_baseu-2.8.so on a different system (one with newer version of GCC), and copied it to the current system, or
    - you've linked libwx_baseu-2.8.so with a newer GCC on the same system, but now are trying to link the executable with an older GCC.

    0 讨论(0)
  • 2021-02-06 04:35

    Try : putting -fno-inline in your flags in Makefile. Basically g++4.4 is having issues without it. Try to put it OR remove the -O option. It solved the same problem I had.

    0 讨论(0)
提交回复
热议问题