CMake 错误:链接器命令失败,退出代码为 1 和 cpp.o 文件
CMake error: linker command failed with exit code 1 and cpp.o files
我正在使用CMake编译一个小项目。
以下是我在CMakeLists中写的内容.txt:
cmake_minimum_required(VERSION 3.2)
set (CMAKE_CXX_STANDARD 11)
project(DAF)
find_package(OpenCV REQUIRED)
include_directories(include)
include_directories(${OpenCV_INCLUDE_DIRS} )
file(GLOB Src_Sources "src/*.cpp")
file(GLOB Test_Sources "test/*.cpp")
add_executable(executable ${Src_Sources} ${Test_Sources})
target_link_libraries( executable include ${OpenCV_LIBS} )
我有两个目录 src 和测试。src 目录仅包含保存函数的文件,而测试目录包含主文件。
一旦我使用cmake
命令,然后使用make
命令,我就会收到此错误:
Scanning dependencies of target executation
[ 25%] Building CXX object CMakeFiles/executation.dir/src/image.cpp.o
[ 50%] Building CXX object CMakeFiles/executation.dir/test/starter_1.cpp.o
[ 75%] Linking CXX executable executation
ld: library not found for -linclude
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make[2]: *** [executation] Error 1
make[1]: *** [CMakeFiles/executation.dir/all] Error 2
make: *** [all] Error 2
所以我觉得奇怪的是它会创建.cpp.o
文件。这正常吗?
然后我该如何修复错误library not found for -linclude
?
是的,CMake 采用源文件的名称并在编译相应的目标文件时附加.o
是正常的。例如,源文件image.cpp
将被编译成image.cpp.o
.CMake 生成的生成文件将包含每个源文件的唯一目标<someSourceFileName>.o
,其中<someSourceFileName>
可以是.cc
、.cpp
、.c
等。
错误:
ld: library not found for -linclude
表示您已尝试将名为include
的库链接到可执行文件。这可能不是您的意图。看起来include
实际上是您的包含目录,并且您已经使用以下行在 CMake 中指定了包含目录:
include_directories(include)
要消除错误,只需从target_link_libraries()
命令中取出include
,如下所示:
target_link_libraries( executable ${OpenCV_LIBS} )
相关文章:
- C++代码以测试另一个.cpp如果可以编译它
- C++(.cpp文件和.h文件)拆分代码并添加一个函数,提取 - 这很容易吗?
- 如何使用可视化代码和平台IO将环境变量注入CPP文件?
- 如何将代码划分为多个.cpp文件 C++.
- CMake 错误:链接器命令失败,退出代码为 1 和 cpp.o 文件
- 如何将默认代码添加到我在 vim 中打开的每个 cpp 文件?
- 无法使用犰狳运行编译的 cpp 代码,因为 dyld:库未加载
- Windows Toast 通知不适用于 MS CPP 示例代码
- 如何大致将 cpp 代码结构转换为 python
- 如何检测 cpp 代码中的 openvino 设备
- cpp / c ++中的grpc客户端代码,元数据x-api-key/x-goog-api-key不起作用,给了我语音A
- 使用指针编译代码后,.cpp文件将变为随机字符
- 在cpp中使用boost-python的python代码是否进行动态内存分配
- Cpp代码故障(显示意外数字)
- CPP代码中出现FileNotFound异常
- 为什么代码会崩溃?(在CPP中)
- 在.cpp文件中定义方法而不是在 C++ 的 .h 文件中定义方法时,如何提高代码的性能?
- 如何使用 AIDEL-CPP 生成 .aidl 到 C++ 代码
- 代码块始终在项目中运行 main.cpp
- CPP DLL 自定义操作代码在安装过程中未执行