Reputation: 24111
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?
Upvotes: 0
Views: 8223
Reputation: 1
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)
Upvotes: 0
Reputation: 704
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
Upvotes: 1