Undefined reference to symbol, DSO missing from command line - c++

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

For me this does the trick
set (CMAKE_CXX_LINK_EXECUTABLE "${CMAKE_CXX_LINK_EXECUTABLE} -ldl")
Useful links
Link1
Link2
Link3 <- Cmake how to find libraries
Link4
Link5

DSO means Dynamic Shared Object. Add the option "-lpthread" works for me.

Related

undefined reference compiling taskwarrior on arm chromebook

I tried to build task-2.5.1 on my armv81 chromebook inside a termux session. It didn't work due build dependencies so I installed them then uncompressed and started in a fresh new directory. When I ran make VERBOSE=1 I got an undefined reference to __atomic_fetch_add_4 when linking...
[ 98%] Linking CXX executable lex
cd /data/data/com.termux/files/home/src/task-2.5.1/src && /data/data/com.termux/files/usr/bin/cmake -E cmake_link_script CMakeFiles/lex_executable.dir/link.txt --verbose=1
/data/data/com.termux/files/usr/bin/c++ -Wall -Wsign-compare -Wreturn-type -std=c++11 -stdlib=libc++ -O3 -DNDEBUG -rdynamic CMakeFiles/lex_executable.dir/lex.cpp.o -o lex libtask.a commands/libcommands.a columns/libcolumns.a libtask.a -lgnutls -luuid
/data/data/com.termux/files/usr/bin/arm-linux-androideabi-ld: libtask.a(Nibbler.cpp.o): in function `Nibbler::Nibbler(Nibbler const&)':
Nibbler.cpp:(.text+0x8c): undefined reference to `__atomic_fetch_add_4'
/data/data/com.termux/files/usr/bin/arm-linux-androideabi-ld: libtask.a(Nibbler.cpp.o): in function `Nibbler::operator=(Nibbler const&)':
Nibbler.cpp:(.text+0xe0): undefined reference to `__atomic_fetch_add_4'
/data/data/com.termux/files/usr/bin/arm-linux-androideabi-ld: Nibbler.cpp:(.text+0x104): undefined reference to `__atomic_fetch_add_4'
/data/data/com.termux/files/usr/bin/arm-linux-androideabi-ld: libtask.a(Nibbler.cpp.o): in function `Nibbler::~Nibbler()':
Nibbler.cpp:(.text+0x174): undefined reference to `__atomic_fetch_add_4'
clang-8: error: linker command failed with exit code 1 (use -v to see invocation)
make[2]: *** [src/CMakeFiles/lex_executable.dir/build.make:90: src/lex] Error 1
make[2]: Leaving directory '/data/data/com.termux/files/home/src/task-2.5.1'
make[1]: *** [CMakeFiles/Makefile2:175: src/CMakeFiles/lex_executable.dir/all] Error 2
make[1]: Leaving directory '/data/data/com.termux/files/home/src/task-2.5.1'
make: *** [Makefile:152: all] Error 2
I found this discussion about undefined references in arm builds. I tried adding a -latomic to CMakeFiles/task_executable.dir/link.txt but it didn't change the output.
Any ideas how to fix this?
Many thanks to wbsch in this issue (posted just after this one) for the link to the known fix which was successful on my machine, removing the three lines from CMakeLists.txt.

collect2.exe: error: ld returned 5 exit status

I've recently updated all msys2 packages and now I can't build my project.
The error occurs at the moment of linking one of .dlls - target_library.dll.
The error message isn't clear to me. What does status 5 mean?
collect2.exe: error: ld returned 5 exit status
Full message:
g++ -Wl,-s,--relax,--gc-sections -shared -Wl,-subsystem,windows -mthreads -Wl,--out-implib,C:/msys64/workspace/Project_Root_Directory/project/src/../build/release/plugins/libtarget_library.dll.a -o ../../../../build/release/plugins/target_library.dll object_script.target_library.Release -lglu32 -lopengl32 -luser32 -LC:/msys64/workspace/Project_Root_Directory/project/build/release -LC:/msys64/workspace/Project_Root_Directory/project/third-party/out/lib -LC:/msys64/workspace/Project_Root_Directory/project/deps/lib -lexif -ldecimal -lsqlite3 -lutils -LC:/Python35/libs -lpython35 -lkmlbase -lkmlengine -lkmldom -lkmlxsd -lminizip -luriparser -lkmlconvenience -lcore -lrender -lraster -lgui -LC:/msys64/workspace/Project_Root_Directory/project/deps/lib/target_library/win64 -LC:/msys64/mingw64/lib C:/msys64/mingw64/lib/libQt5Widgets.dll.a C:/msys64/mingw64/lib/libQt5WinExtras.dll.a C:/msys64/mingw64/lib/libQt5Gui.dll.a C:/msys64/mingw64/lib/libQt5Network.dll.a C:/msys64/mingw64/lib/libQt5Concurrent.dll.a C:/msys64/mingw64/lib/libQt5Xml.dll.a C:/msys64/mingw64/lib/libQt5Core.dll.a
collect2.exe: error: ld returned 5 exit status
make[4]: *** [Makefile.Release:159: ../../../../build/release/plugins/target_library.dll] Error 1
make[4]: Leaving directory '/workspace/Project_Root_Directory/project/src/modules/plugins/target_library'
make[3]: Leaving directory '/workspace/Project_Root_Directory/project/src/modules/plugins/target_library'
make[2]: *** [Makefile:384: sub-target_library-make_first] Error 2
make[2]: Leaving directory '/workspace/Project_Root_Directory/project/src/modules/plugins'
make[1]: *** [Makefile:297: sub-plugins-make_first] Error 2
make[1]: Leaving directory '/workspace/Project_Root_Directory/project/src/modules'
make: *** [Makefile:44: sub-modules-make_first] Error 2
gcc 7.1.0, Qt5 5.9.1, qmake, Win7 x64
I had the same issue.
I link my project with static library.
After mingw64 upgrade, my project stoped building with the same error.
I found out that debug version built successfully. So i compared linker flags. In release version Qt add this flags "-Wl,-s,--relax,--gc-section".
I couldn't find any information about "-s" flag, but due to this link i figured out that -gc-section flag was the reason of fail.
I added the following code to my .pro-file, and it worked
mingw {
contains(QT_ARCH, x86_64): {
LIBS+=-Wl,--no-gc-sections
}
}
Just in case someone finds this due the same problem, please, add the following flag to your compiler -Wl,--verbose (or --verbose to the linker). This will show which library was not found or give you more information about the problem.

Linking library with gcc - ld: cannot find -larpack

I am installing software on a server with no root privileges. I come across the following error during installation:
make[1]: *** [hgaprec] Error 1
make[1]: Leaving directory `/seq/.../SOFTWARE/hgaprec/src'
make: *** [all-recursive] Error 1
Making install in src
make[1]: Entering directory `/seq/.../SOFTWARE/hgaprec/src'
g++ -O3 -o hgaprec ratings.o main.o log.o hgaprec.o -larpack -llapack -
lblas -lgsl -lpthread -lgslcblas
/.../software/free/Linux/redhat_6_x86_64/pkgs/gcc_5.2.0/bin/ld: cannot
find -larpack
collect2: error: ld returned 1 exit status
make[1]: *** [hgaprec] Error 1
make[1]: Leaving directory `/seq/.../SOFTWARE/hgaprec/src'
make: *** [install-recursive] Error 1
Since library arpack could not be found, I then installed it here /seq/.../SOFTWARE/hgaprec/ARPACK and found that the process generated a static file libarpack_LINUX.a. To link this static library to gcc the following command was used:
gcc -larpack -L/seq/.../SOFTWARE/hgaprec/ARPACK/libarpack_LINUX.a
However, I keep getting the same error while installation of the software that larpack was not found. Am I using the linking command wrong?
You either want gcc main.c /seq/../SOFTWARE/hgaprec/ARPACK/libarpack_LINUX.a (you don't need -l and -L if you're specifying the full path to static library), or as #Julian_Cienfuegos suggested gcc main.c -L/seq/../SOFTWARE/hgaprec/ARPACK/ -larpack_LINUX. This assumes you're only compiling a single file called main.c which contains your main() function, and outputs the a.out binary.
EDIT: Added explanation of main.c.
My issue got solved after including the ARPACK library path as part of LD flag in configure like so:
./configure --prefix=/seq/.../SOFTWARE/hgaprec LDFLAGS="-L/seq/.../SOFTWARE/hgaprec/ARPACK/"

Error during make: error adding symbols: DSO missing from command line

I am trying to compile some code downloaded from a git repository (OpenNI2, https://github.com/occipital/OpenNI2). I am getting the following errors after running make:
make -C Source/Tools/NiViewer
make[1]: Entering directory `/home/karnivaurus/Data/Libraries/OpenNI2/Source/Tools/NiViewer'
g++ -o ../../../Bin/x64-Release/NiViewer ./../../../Bin/Intermediate/x64-Release/NiViewer/Device.o ./../../../Bin/Intermediate/x64-Release/NiViewer/Draw.o ./../../../Bin/Intermediate/x64-Release/NiViewer/Keyboard.o ./../../../Bin/Intermediate/x64-Release/NiViewer/Menu.o ./../../../Bin/Intermediate/x64-Release/NiViewer/MouseInput.o ./../../../Bin/Intermediate/x64-Release/NiViewer/NiViewer.o ./../../../Bin/Intermediate/x64-Release/NiViewer/Capture.o -L../../../ThirdParty/PSCommon/XnLib/Bin/x64-Release -L../../../Bin/x64-Release -lglut -lGL -lOpenNI2 -lXnLib -Wl,-rpath ./
/usr/bin/ld: ../../../ThirdParty/PSCommon/XnLib/Bin/x64-Release/libXnLib.a(XnLinuxMutex.o): undefined reference to symbol 'pthread_mutexattr_settype##GLIBC_2.2.5'
//lib/x86_64-linux-gnu/libpthread.so.0: error adding symbols: DSO missing from command line
collect2: error: ld returned 1 exit status
make[1]: *** [../../../Bin/x64-Release/NiViewer] Error 1
make[1]: Leaving directory `/home/karnivaurus/Data/Libraries/OpenNI2/Source/Tools/NiViewer'
make: *** [Source/Tools/NiViewer] Error 2
Any ideas on how I should go about solving this?
You have to add the directive "-lpthread" to your compiler and it is solved.
for instance if your previous code was:
g++ mycode.cpp -o myexecutable
Now you have to put
g++ mycode.cpp -lpthread -o myexecutable
You need add the pthread library into the target_link_libraries. You can edit your CMakeLists.txt file as follow. This solution works for me.
target_link_libraries(ExcutableFileName ${Existed_LIBRARY})
-->
target_link_libraries(ExcutableFileName ${Existed_LIBRARY} pthread)

using a custom compiler flag in cmake?

I'm trying to compile some code I found on GitHub https://github.com/tapio/Wendy
I'm just trying to compile the stuff in tests/. I never had any experience with cmake, but they're kinda logical anyway.
I got stuck at the part where cmake does this:
/usr/bin/c++ CMakeFiles/clear.dir/clear.o -o clear -rdynamic -lwendy -lglfw -lGLEW -lglm -lz
and gets this error:
Linking CXX executable clear
/usr/bin/ld: cannot find -lwendy
/usr/bin/ld: cannot find -lglm
collect2: ld returned 1 exit status
make[3]: *** [clear] Error 1
make[2]: *** [CMakeFiles/clear.dir/all] Error 2
make[1]: *** [CMakeFiles/clear.dir/rule] Error 2
make: *** [clear] Error 2
I don't understand how the Wendy and glm folder became a compiler flag. Somebody please explain how this is possible. :(
In tests/CMakeLists.txt the line target_link_libraries(${test} wendy ${WENDY_LIBRARIES}) instructs cmake to link the list of libraries in WENDY_LIBRARIES to the executable.