2

这是编译时的输出,我达到 100%,然后链接失败,可能是由于缺少 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

我已经尝试过很多次弄乱 CMakeLists 文件,这是我尝试过的一些事情:

  • 添加FIND_PACKAGE (Threads)
  • 添加TARGET_LINK_LIBRARIES(pthread)(导致 cmake 错误)

任何帮助将不胜感激,谢谢。

4

1 回答 1

1

并将其添加到主(根)CMakeLists:

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

有一个子 CMakeLists 在src/gnc。我在其中添加了这个:

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

它现在可以干净地编译。

于 2013-10-07T10:29:14.850 回答