使用cmake链接错误
Linking error using cmake
我正在使用cmake编译一些代码,但遇到了错误。这是我收到的信息:
[ 79%] Linking CXX executable ../release/report_intr_dim
/usr/bin/ld: ../release/libNonMetricSpaceLib.a(pivot_neighb_invindx.cc.o): undefined reference to symbol 'pthread_create@@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
test/CMakeFiles/report_intr_dim.dir/build.make:99: recipe for target 'release/report_intr_dim' failed
make[2]: *** [release/report_intr_dim] Error 1
CMakeFiles/Makefile2:326: recipe for target 'test/CMakeFiles/report_intr_dim.dir/all' failed
make[1]: *** [test/CMakeFiles/report_intr_dim.dir/all] Error 2
Makefile:127: recipe for target 'all' failed
make: *** [all] Error 2
Makefile:127:
[126]all: cmake_check_build_system
[127] $(CMAKE_COMMAND) -E cmake_progress_start /home/safarisoul/nns_benchmark-master/algorithms/NMSLIB/code/CMakeFiles /home/safarisoul/nns_benchmark-master/algorithms/NMSLIB/code/CMakeFiles/progress.marks
[128] $(MAKE) -f CMakeFiles/Makefile2 all
[129] $(CMAKE_COMMAND) -E cmake_progress_start /home/safarisoul/nns_benchmark-master/algorithms/NMSLIB/code/CMakeFiles 0
[130].PHONY : all
CMakeFiles/Makefile2:326:
[323]# All Build rule for target.
[324]test/CMakeFiles/report_intr_dim.dir/all: lshkit/CMakeFiles/lshkit.dir/all
[325]test/CMakeFiles/report_intr_dim.dir/all: src/CMakeFiles/NonMetricSpaceLib.dir/all
[326] $(MAKE) -f test/CMakeFiles/report_intr_dim.dir/build.make test/CMakeFiles/report_intr_dim.dir/depend
[327] $(MAKE) -f test/CMakeFiles/report_intr_dim.dir/build.make test/CMakeFiles/report_intr_dim.dir/build
[328] @$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --progress-dir=/home/safarisoul/nns_benchmark-master/algorithms/NMSLIB/code/CMakeFiles --progress-num=93,94 "Built target report_intr_dim"
[329].PHONY : test/CMakeFiles/report_intr_dim.dir/all
[330]
[331]# Include target in all.
[332]all: test/CMakeFiles/report_intr_dim.dir/all
[333]
[334].PHONY : all
test/CMakeFiles/report_intr_dim.dir/build.make:99:
[88]# External object files for target report_intr_dim
[89]report_intr_dim_EXTERNAL_OBJECTS =
[90]
[91]release/report_intr_dim: test/CMakeFiles/report_intr_dim.dir/report_intr_dim.cc.o
[92]release/report_intr_dim: test/CMakeFiles/report_intr_dim.dir/build.make
[93]release/report_intr_dim: release/libNonMetricSpaceLib.a
[94]release/report_intr_dim: release/liblshkit.a
[95]release/report_intr_dim: /usr/lib/x86_64-linux-gnu/libboost_system.so
[96]release/report_intr_dim: /usr/lib/x86_64-linux-gnu/libboost_filesystem.so
[97]release/report_intr_dim: /usr/lib/x86_64-linux-gnu/libboost_program_options.so
[98]release/report_intr_dim: test/CMakeFiles/report_intr_dim.dir/link.txt
[99] @$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --green --bold --progress-dir=/home/safarisoul/nns_benchmark-master/algorithms/NMSLIB/code/CMakeFiles --progress-num=$(CMAKE_PROGRESS_2) "Linking CXX executable ../release/report_intr_dim"
[100] cd /home/safarisoul/nns_benchmark-master/algorithms/NMSLIB/code/test && $(CMAKE_COMMAND) -E cmake_link_script CMakeFiles/report_intr_dim.dir/link.txt --verbose=$(VERBOSE)
我在谷歌上搜索了一下,意识到我需要在某个地方添加"-phread",我可能应该在CMakeLists.txt中修改一些内容。但这是我第一次使用cmake,我不熟悉c/c++。我不知道该怎么解决这个问题。请帮忙。
假设这真的与缺失的pthread链接,这是在CMakeLists.txt中应该如何完成的当前方式:
find_package(Threads REQUIRED)
[..]
target_link_libraries(target [SCOPE] Threads::Threads)
使用CMake
:链接pthreads
find_package(Threads REQUIRED)
target_link_libraries(NonMetricSpaceLib Threads::Threads)
如果有多个线程库,可以尝试设置CMAKE_THREAD_PREFER_PTHREAD
和THREADS_PREFER_PTHREAD_FLAG
。
- https://cmake.org/cmake/help/latest/command/target_link_libraries.html
- https://cmake.org/cmake/help/latest/module/FindThreads.html
相关文章:
- Netbeans 10:错误:链接器命令失败,退出代码为 1(使用 -v 查看调用)
- CMake 错误:链接器命令失败,退出代码为 1 和 cpp.o 文件
- clang:错误:链接器命令失败,退出代码为 1(使用 -v 查看调用) - 体系结构的未定义符号 x86_64:
- 如何修复 clang: 错误:链接器命令失败,退出代码为 1(使用 -v 查看调用)
- Android NDK.Build命令失败.未定义的引用.clang++:错误:链接器命令失败,退出代码为1
- 使用cmake错误链接boost日志
- 错误:链接器命令失败,退出代码为 1(使用 -v 查看调用):在 Macbook 上
- C++ XCODE ld:找不到体系结构x86_64 clang 的符号:错误:链接器命令失败,退出代码为 1(使用 -
- clang:错误:链接器命令失败,C++代码中的退出代码为 1(使用 -v 查看调用)
- 静态库中的 g++ 错误链接函数
- 未定义的参考错误链接天然函数Android
- C++编译错误:ld:找不到体系结构x86_64 clang 的符号:错误:链接器命令失败,退出代码为 1(使用 -v
- QT Q_PROPERTY错误:链接器命令失败,退出代码为 1(使用 -v 查看调用)
- ld:找不到体系结构x86_64 clang 的符号:错误:链接器命令失败,退出代码为 1(使用 -v 查看调用)
- OSX MOJAVE -LD:架构X86_64 clang找不到符号:错误:链接器命令失败,出口代码1
- C 错误链接器命令失败了出口代码1(使用-V查看调用)
- LD:架构x86_64 clang找不到符号:错误:链接器命令失败,出口代码1(使用-v to See
- 聚输出错误 - 链接列表
- Xcode链接器错误:链接器命令失败,退出代码为1(使用-v查看调用)
- 尝试构建C DLIB示例无法与数百个未定义的参考错误链接