Not having ability to link pthreads to resolve cmake compiling issue

1.5k Views Asked by At

Here is the output when compiling, I get to 100% then when linking it fails, presumably due to missing pthreads

cd /home/username/code/gnucash/build/src/gnc && /usr/bin/cmake -E cmake_link_script CMakeFiles/cutecash.dir/link.txt --verbose=1
/usr/bin/c++       CMakeFiles/cutecash.dir/moc_AccountItemModel.cxx.o CMakeFiles/cutecash.dir/moc_AccountSelectionDelegate.cxx.o CMakeFiles/cutecash.dir/moc_RecentFileMenu.cxx.o CMakeFiles/cutecash.dir/moc_SplitListModel.cxx.o CMakeFiles/cutecash.dir/moc_SplitListView.cxx.o CMakeFiles/cutecash.dir/moc_mainwindow.cxx.o CMakeFiles/cutecash.dir/moc_dashboard.cxx.o CMakeFiles/cutecash.dir/fpo/moc_FPO.cxx.o CMakeFiles/cutecash.dir/fpo/moc_ViewletModel.cxx.o CMakeFiles/cutecash.dir/fpo/moc_ViewletView.cxx.o CMakeFiles/cutecash.dir/qrc_gnucash.cxx.o CMakeFiles/cutecash.dir/qrc_gtk-icons.cxx.o CMakeFiles/cutecash.dir/qrc_fallback-icons.cxx.o CMakeFiles/cutecash.dir/qrc_stylesheets.cxx.o CMakeFiles/cutecash.dir/AccountItemModel.cpp.o CMakeFiles/cutecash.dir/AccountSelectionDelegate.cpp.o CMakeFiles/cutecash.dir/Cmd.cpp.o CMakeFiles/cutecash.dir/QofEventWrapper.cpp.o CMakeFiles/cutecash.dir/RecentFileMenu.cpp.o CMakeFiles/cutecash.dir/Session.cpp.o CMakeFiles/cutecash.dir/SplitListModel.cpp.o CMakeFiles/cutecash.dir/SplitListView.cpp.o CMakeFiles/cutecash.dir/main.cpp.o CMakeFiles/cutecash.dir/mainwindow.cpp.o CMakeFiles/cutecash.dir/mainwindow-file.cpp.o CMakeFiles/cutecash.dir/dashboard.cpp.o CMakeFiles/cutecash.dir/fpo/FPO.cpp.o CMakeFiles/cutecash.dir/fpo/ViewletModel.cpp.o CMakeFiles/cutecash.dir/fpo/ViewletView.cpp.o  -o cutecash -rdynamic ../backend/xml/libgnc-backend-xml.a ../import-export/libgnc-import.a ../app-utils/libapp-utils.a ../optional/gtkmm/liblibgncmod-gtkmm.a ../engine/libengine.a ../gnc-module/libgnc-module.a ../core-utils/libcore-utils.a ../libqof/libqof.a -lguile -lgmp -lcrypt -lm -lltdl -lglibmm-2.4 -lgobject-2.0 -lsigc-2.0 -lglib-2.0 -lgconf-2 -lglib-2.0 -lgthread-2.0 -lglib-2.0 -lgobject-2.0 -lglib-2.0 -lgmodule-2.0 -lglib-2.0 -lglib-2.0 -lxml2 -lQtGui -lQtCore -lgobject-2.0 -lsigc-2.0 -lgconf-2 -lgthread-2.0 -lgmodule-2.0 -lxml2 -lQtGui -lQtCore 
/usr/bin/ld: CMakeFiles/cutecash.dir/main.cpp.o: undefined reference to symbol 'pthread_getspecific@@GLIBC_2.2.5'
/usr/bin/ld: note: 'pthread_getspecific@@GLIBC_2.2.5' is defined in DSO /lib/x86_64-linux-gnu/libpthread.so.0 so try adding it to the linker command line
/lib/x86_64-linux-gnu/libpthread.so.0: could not read symbols: Invalid operation
collect2: error: ld returned 1 exit status
make[2]: *** [src/gnc/cutecash] Error 1
make[2]: Leaving directory `/home/username/code/gnucash/build'
make[1]: *** [src/gnc/CMakeFiles/cutecash.dir/all] Error 2
make[1]: Leaving directory `/home/username/code/gnucash/build'
make: *** [all] Error 2

I have tried messing with the CMakeLists file a lot, here are some of the things I tried:

  • adding FIND_PACKAGE (Threads)
  • adding TARGET_LINK_LIBRARIES(pthread) (causes cmake error)

Any help would be greatly appreciated, thanks.

1

There are 1 best solutions below

0
On

And added this to the main (root)CMakeLists:

include_directories( ${ZLIB_INCLUDE_DIRS} )
FIND_PACKAGE (ZLIB REQUIRED)
FIND_PACKAGE (Threads)

There is a child CMakeLists at src/gnc. I added this to it:

target_link_libraries ( cutecash ${CMAKE_THREAD_LIBS_INIT} )
target_link_libraries( cutecash ${ZLIB_LIBRARIES} )

And it now compiles cleanly.