- undefined reference to symbol ‘socket@GLIBC_2.4’ while linking
- Undefined Reference to Symbol » . Error Adding Symbols: DSO Missing From Command Line (With CMake)
- undefined reference to symbol even when nm indicates that this symbol is present in the shared library
- Undefined reference to symbol, DSO missing from command line
- 2 Answers 2
undefined reference to symbol ‘socket@GLIBC_2.4’ while linking
I’m migrating from the default armhf cross compilation toolchain for ubuntu, to a precompiled toolchain from bootlin.com in order to have more control over the glibc version for a project. Specifically, I’m using glibc 2.26 and gcc 6.4.0 However, I’ve been unable to succesfully link the project. While linking, I get the error
/opt/glibc/arm-buildroot-linux-gnueabihf/bin/ld: ./src/foo.o: undefined reference to symbol 'socket@@GLIBC_2.4' /opt/glibc/lib/gcc/arm-buildroot-linux-gnueabihf/sysroot/lib/libc.so.6: error adding symbols: DSO missing from command line collect2: error: ld returned 1 exit status
"/opt/glibc/bin/arm-buildroot-linux-gnueabihf-g++" -std=c++03 \ -nostdinc -nostdinc++ \ "-I"/opt/glibc/arm-buildroot-linux-gnueabihf/include/c++/6.4.0/"" \ "-I"/opt/glibc/arm-buildroot-linux-gnueabihf/include/c++/6.4.0/"/arm-linux-gnueabihf" \ "-I"/opt/glibc/arm-buildroot-linux-gnueabihf/include/c++/6.4.0/"/backward" \ "-I"/opt/glibc/arm-buildroot-linux-gnueabihf/include/c++/6.4.0/"/arm-buildroot-linux-gnueabihf" \ "-I"/opt/glibc/lib/gcc/arm-buildroot-linux-gnueabihf/6.4.0"/include" \ "-I"/opt/glibc/lib/gcc/arm-buildroot-linux-gnueabihf/6.4.0"/include-fixed" \ "-I"/opt/glibc/arm-buildroot-linux-gnueabihf/sysroot"/usr/include"" \ -I/opt/glibc/bin/../arm-buildroot-linux-gnueabihf/sysroot/usr/include/json-c -I/opt/glibc/bin/../arm-buildroot-linux-gnueabihf/sysroot/usr/include -I../3rdparty \ -O3 -Wall -Wextra -pedantic -c -fmessage-length=0 -MMD -MP -MF"src/foo.d" -MT"src/foo.d" -o "src/foo.o" "../src/foo.cpp"
"/opt/glibc/bin/arm-buildroot-linux-gnueabihf-g++" -v -o "out" \ -nostdlib -nostartfiles \ ""/opt/glibc/arm-buildroot-linux-gnueabihf/sysroot"/usr/lib/crti.o" "/opt/glibc//lib/gcc/arm-buildroot-linux-gnueabihf/6.4.0"/crtbegin.o \ ./src/foo.o ./src/bar.o \ -Wl,-Bstatic -L/opt/glibc/bin/../arm-buildroot-linux-gnueabihf/sysroot/usr/lib -ljson-c \ -Wl,-Bdynamic "-L"/opt/glibc/arm-buildroot-linux-gnueabihf/sysroot"/lib" "-L"/opt/glibc/arm-buildroot-linux-gnueabihf/sysroot"/usr/lib" "-L/opt/glibc/lib" -lrt -pthread -L/opt/glibc/bin/../arm-buildroot-linux-gnueabihf/sysroot/usr/lib -lbluetooth \ "/opt/glibc/lib/gcc/arm-buildroot-linux-gnueabihf/6.4.0"/crtend.o ""/opt/glibc/arm-buildroot-linux-gnueabihf/sysroot"/usr/lib/crtn.o"
Undefined Reference to Symbol » . Error Adding Symbols: DSO Missing From Command Line (With CMake)
Quick overview of the problem: I am writing a project and was able to get the code I had written (so far) to compile, so I thought to myself I should start writing an example executable to make sure everything is working as I intended. I am a novice at C++ and even more of a novice at CMake (so forgive me if the code doesn’t look well). After creating the ground work for the executable file I decided to make it and I ended up getting the error:
/usr/bin/ld: CMakeFiles/oneLinkAdaptive.dir/oneLinkAdaptiveExample.cpp.o: undefined reference to symbol '_ZN5robot12configurator16initializeParamsEPKc' /usr/bin/ld: //home/pi/Desktop/cfucr/build/src/configurator/libconfigurator-libs.so: error adding symbols: DSO missing from command line collect2: error: ld returned 1 exit status make[2]: *** [src/examples/CMakeFiles/oneLinkAdaptive.dir/build.make:86: src/examples/oneLinkAdaptive] Error 1 make[1]: *** [CMakeFiles/Makefile2:46987: src/examples/CMakeFiles/oneLinkAdaptive.dir/all] Error 2 make: *** [Makefile:130: all] Error 2
From my understanding this is actually a CMake error and that I’m either failing to add a library or maybe I am failing to find a function in my C++ code I wrote(?):
namespace robot < namespace configurator < std::tupleinitializeParams(const char* configFile); .
(I am less inclined to believe the C++ code is what's wrong, but honestly I have no idea at this point.) I have done some snooping around online and tried some things from other posts, i.e., moving the library around to make sure the libsconfigurator-libs library was being creating before adding the executable to CMake, checking to make sure I was actually including the libsconfigurator-libs library, changing things from PRIVATE to PUBLIC , etc. The main src CMake file is written as:
# Add controller main files # add_library(cfucr-libs controller.cpp controller.hpp ) # Add the `src` directory to be included # set(CFUCR_BASE_DIR $) include_directories( $ ) # Add a list of subdirectories # add_subdirectory(configurator) add_subdirectory(control) add_subdirectory(filter) add_subdirectory(mathUtilities) add_subdirectory(thirdParty) add_subdirectory(types) target_link_libraries(cfucr-libs PRIVATE configurator-libs control-libs filter-libs math-utilities-libs type-libs tinyxml2 eigen ) add_subdirectory(examples)
The executable file is located down in the examples sub-directory, so I moved that add_subdirectory to the bottom of the file. That way, I could make sure to add all of the other libraries I created to the main cfucr library. The examples CMake file is written as:
# Add controller example main files # add_library(examples-libs oneLinkAdaptiveExample.cpp ) # Make executable files for controller examples # add_executable(oneLinkAdaptive oneLinkAdaptiveExample.cpp ) target_link_libraries(oneLinkAdaptive PRIVATE cfucr-libs examples-libs )
Basically, to just create the executable and add the main library to it. The configurator library is super simple and is given as:
# Add configurator files # add_library(configurator-libs configurator.cpp configurator.hpp )
I have been trying to fix this for a bit now but nothing seems to work/I don't fully understand how all of this works to really be able to fix the problem on my own. If anyone has any ideas on what I might be doing incorrectly I would love to hear it. Also, if I need to post anything else (any more CMake files or source files) to help make things clearer let me know and I will post them! Thank you!
undefined reference to symbol even when nm indicates that this symbol is present in the shared library
This is happening on Ubuntu 12.04. The libmnl-dev and libmnl0 packages are installed. The strace output of gcc indicates that ld is using exactly that *.so file:
[pid 10988] stat("/usr/lib/gcc/x86_64-linux-gnu/4.6/libmnl.so", 0x7fff2a39b470) = -1 ENOENT (No such file or directory) [pid 10988] open("/usr/lib/gcc/x86_64-linux-gnu/4.6/libmnl.so", O_RDONLY) = -1 ENOENT (No such file or directory) [pid 10988] stat("/usr/lib/gcc/x86_64-linux-gnu/4.6/libmnl.a", 0x7fff2a39b4d0) = -1 ENOENT (No such file or directory) [pid 10988] open("/usr/lib/gcc/x86_64-linux-gnu/4.6/libmnl.a", O_RDONLY) = -1 ENOENT (No such file or directory) [pid 10988] stat("/usr/lib/gcc/x86_64-linux-gnu/4.6/../../../x86_64-linux-gnu/libmnl.so", 0x7fff2a39b470) = -1 ENOENT (No such file or directory) [pid 10988] open("/usr/lib/gcc/x86_64-linux-gnu/4.6/../../../x86_64-linux-gnu/libmnl.so", O_RDONLY) = -1 ENOENT (No such file or directory) [pid 10988] stat("/usr/lib/gcc/x86_64-linux-gnu/4.6/../../../x86_64-linux-gnu/libmnl.a", 0x7fff2a39b4d0) = -1 ENOENT (No such file or directory) [pid 10988] open("/usr/lib/gcc/x86_64-linux-gnu/4.6/../../../x86_64-linux-gnu/libmnl.a", O_RDONLY) = -1 ENOENT (No such file or directory) [pid 10988] stat("/usr/lib/gcc/x86_64-linux-gnu/4.6/../../../../lib/libmnl.so", ) = 0 [pid 10988] open("/usr/lib/gcc/x86_64-linux-gnu/4.6/../../../../lib/libmnl.so", O_RDONLY) = 7
Undefined reference to symbol, DSO missing from command line
I'm trying to compile the Lotech framework under Debian Jessie, but I'm can't seem to get past a specific point in compilation. I've searched the error messages that come up, and almost all of them seem to be resolved by installing or linking a missing dependency, but I can't figure out what that dependency is in this situation.
cp buildtmp.linux/liblt.a linux/ cd clients/glfw/ && make LTCFLAGS="-O3 -DNDEBUG -DLTLINUX " && cp ltclient ../../ make[1]: Entering directory `/home/jake/Desktop/copy-lotech-master/clients/glfw' g++ -O3 -DNDEBUG -DLTLINUX -I../../linux/include -L../../linux ltclient.cpp \ -o ltclient -static-libstdc++ -static-libgcc ../../linux/liblt.a ../../linux/libpng.a ../../linux/libz.a ../../linux/liblua.a ../../linux/libvorbis.a ../../linux/libbox2d.a ../../linux/libglfw.a ../../linux/libGLEW.a ../../linux/libopenal.a ../../linux/libcurl.a -lX11 -lGL wrap_memcpy.o -Wl,--wrap=memcpy /usr/bin/ld: ../../linux/libopenal.a(helpers.o): undefined reference to symbol 'dlclose@@GLIBC_2.2.5' //lib/x86_64-linux-gnu/libdl.so.2: error adding symbols: DSO missing from command line collect2: error: ld returned 1 exit status make[1]: *** [ltclient] Error 1 make[1]: Leaving directory `/home/jake/Desktop/copy-lotech-master/clients/glfw' make: *** [ltclient] Error 2
2 Answers 2
For me this does the trick
DSO means Dynamic Shared Object. Add the option "-lpthread" works for me.
when you way "works for me", do you actually mean you reproduced the asker's exact problem scenario and solved it in this way? Or are you referring to a separate problem that you were personally facing? Gelldur's answer involves linking to a DLL-related library, and the asker's error message refers to a DLL-related function. I can't see how libpthread would fix a missing DLL symbol.
Yes, I got the error message as the asker's. The error was gone after I added "-lpthread" option in linking stage.
Interesting. If you have more insight into why this error occurs and why this fixes it, that would be a great addition to your answer.