简体   繁体   English

如何避免在 cmake 中自动链接 Qt5 库?

[英]how avoid automatic linking of Qt5 libraries in cmake?

I am intending to compile the following opencv code:我打算编译以下 opencv 代码:

#include <stdio.h>
#include <opencv2/opencv.hpp>

using namespace cv;

int main(int argc, char** argv )
{
   printf("hello world \n");
   return 0;
}

My CMakeLists.txt is the following:我的 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} )

When compiled the result is as follows:编译后的结果如下:

[ 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

I believe that CMake in automatic way include Qt5 libraries, I would want to know how avoid this situation.我相信 CMake 以自动方式包含 Qt5 库,我想知道如何避免这种情况。

Ideology of CMake is to never add something that is not required. CMake 的理念是永远不要添加不需要的东西。 It is possible that Qt libs were added to configuration list of CMake. Qt 库可能已添加到 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.配置文件看起来像OpenCVConfig.cmake.in并且可能包含由于某种原因被更改的其他文件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM