c++ - 如何避免在 cmake 中自动链接 Qt5 库?
问题描述
我打算编译以下opencv代码:
#include <stdio.h>
#include <opencv2/opencv.hpp>
using namespace cv;
int main(int argc, char** argv )
{
printf("hello world \n");
return 0;
}
我的 CMakeLists.txt 如下:
cmake_minimum_required(VERSION 2.8)
find_package( OpenCV REQUIRED )
project( main )
add_executable(main main.cpp )
target_link_libraries( main ${OpenCV_LIBS} )
编译后的结果如下:
[ 50%] Building CXX object CMakeFiles/main.dir/main.cpp.o
[100%] Linking CXX executable main
/usr/bin/ld: cannot find -lQt5::Core
/usr/bin/ld: cannot find -lQt5::Gui
/usr/bin/ld: cannot find -lQt5::Widgets
/usr/bin/ld: cannot find -lQt5::Test
/usr/bin/ld: cannot find -lQt5::Concurrent
/usr/bin/ld: cannot find -lQt5::OpenGL
collect2: error: ld returned 1 exit status
CMakeFiles/main.dir/build.make:143: recipe for target 'main' failed
make[2]: *** [main] Error 1
CMakeFiles/Makefile2:67: recipe for target 'CMakeFiles/main.dir/all' failed
make[1]: *** [CMakeFiles/main.dir/all] Error 2
Makefile:83: recipe for target 'all' failed
make: *** [all] Error 2
我相信 CMake 以自动方式包含 Qt5 库,我想知道如何避免这种情况。
解决方案
Ideology of CMake is to never add something that is not required. It is possible that Qt libs were added to configuration list of CMake.
They might be featured in standard variable you use. You can print content by
message(STATUS "OpenCV_LIBS = ${OpenCV_LIBS}")
Configuration file looks OpenCVConfig.cmake.in and may include other files which for some reason were changed.
推荐阅读
- spartacus-storefront - 在 spartacus 中手动加载延迟插槽/组件
- python - 如何将未知对象定义为python类
- rust - 是否可以使用自定义相等运算符进行模式匹配?
- flutter - 如何定位出现在 Flutter 中所有其他元素之上的元素
- python - 如何使用 python 运行 cURL 请求
- sql - 不起作用时按顺序使用表格
- javascript - Oracle Apex 使用 SweetAlert js 代码停止动态操作
- sql - 有没有办法将数组引用到 PostgreSql 中的另一个表?我是通过出错来做到的
- blob - 如何从服务工作者的 localForage 返回 blob 项目?
- html - 有没有办法使用 HTML 和 Thymeleaf 过滤从 Spring Boot 端点返回的数据?