gpt4 book ai didi

ubuntu - 使用cmake时出错

转载 作者:太空宇宙 更新时间:2023-11-03 22:15:41 27 4
gpt4 key购买 nike

我刚刚安装了 OpenCV,并一直在尝试对 DsiplayImage 执行示例。尝试“cmake”时出现以下错误。

~/Desktop$ cmake . CMake Error at CMakeLists.txt:5 (target_link_libraries): Cannot specify link libraries for target "DisplayImage" which is not built by this project.

-- Configuring incomplete, errors occurred!

下面是实际代码:显示图像.cpp

#include <cv.h>
#include <highgui.h>
using namespace cv;

int main( int argc, char** argv )
{
Mat image;
image = imread( argv[1], 1 );

if( argc != 2 || !image.data )
{
printf( "No image data \n" );
return -1;
}

namedWindow( "Display Image", CV_WINDOW_AUTOSIZE );
imshow( "Display Image", image );

waitKey(0);

return 0;
}

CmakeLists.txt

cmake_minimum_required(VERSION 2.8)
project( displayimage )
find_package( OpenCV REQUIRED )
add_executable( displayImage displayimage )
target_link_libraries( displayimage ${OpenCV_LIBS} )

最佳答案

应该是

cmake_minimum_required(VERSION 2.8)
PROJECT( displayimage )
FIND_PACKAGE( OpenCV REQUIRED )
ADD_EXECUTABLE( displayimage displayimage.cpp )
TARGET_LINK_LIBRARIES( displayimage ${OpenCV_LIBS} )

我在我的机器上试过这段代码,它有效。也许是因为所有命令都必须是大写字母!不知道,但它有效干杯:)

关于ubuntu - 使用cmake时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11375245/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com