无法链接 pthreads 来解决 cmake 编译问题
Not having ability to link pthreads to resolve cmake compiling issue
这是编译时的输出,我达到 100% 然后当链接失败时,可能是由于缺少线程
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
我尝试了很多弄乱CMakeList文件,以下是我尝试过的一些事情:
- 添加
FIND_PACKAGE (Threads)
- 添加
TARGET_LINK_LIBRARIES(pthread)
(导致 cmake 错误)
任何帮助将不胜感激,谢谢。
并将其添加到主(根)CMakeLists:
include_directories( ${ZLIB_INCLUDE_DIRS} )
FIND_PACKAGE (ZLIB REQUIRED)
FIND_PACKAGE (Threads)
src/gnc
有一个子 CMakeLists。我添加了这个:
target_link_libraries ( cutecash ${CMAKE_THREAD_LIBS_INIT} )
target_link_libraries( cutecash ${ZLIB_LIBRARIES} )
它现在编译干净。
相关文章:
- 如何使用CMake编译.proto文件来生成.grpcp.pb.cc和.grpc.pb.h文件
- MinGw 无法从 cmake 编译测试文件
- C++CMake编译指令与
- 在windows上使用cmake编译FFTW(OpenMP)
- 无法让 CMAKE 编译项目
- 包含 cmath 标头时出现 cmake 编译错误
- 使用用 C++ 和 DDS 编写的 CMAKE 编译代码
- 使用 cmake 编译带有 v8 库的 C++ 程序
- 在 Windows 上使用 Emscripten 和 CMake 编译 GLFM 的问题
- 如何使用 CMAKE 编译现代 C++ 项目代码
- 使用 Cmake 编译 LZO 时,它注意到找不到任何 VS 实例
- 使用 CMake 编译时,更改头文件的位置会导致缺少 vtable 错误
- 使用LibConfig库的CMAKE编译问题
- 使用 cmake 编译时未定义的引用
- 分段错误,当使用 cmake 编译而不使用 cout 编译时
- 在CLion中使用CMake编译带有参数的C++会引发错误,而在终端中编译则不会
- 如何让 CMake 编译包含 Boost Local Functions 的源文件
- 无法使用CMake编译简单的Opencv C++文件
- 预处理之后和使用CMake编译之前的自定义构建步骤
- 使用 CMake 编译 SFML 应用程序