我遵循这里给出的代码,cmake.html#linux-gcc-usage,这是用GCC和CMAKE编译的。
我保存了一个包含代码的DisplayImage.cpp文件和一个包含相应代码的CMakeLists.txt文件。另外,lena.jpeg也保存在同一个目录中。
DisplayImage.cpp代码
#include <stdio.h>
#include <opencv2/opencv.hpp>
using namespace cv;
int main(int argc, char** argv )
{
if ( argc != 2 )
{
printf("usage: DisplayImage.out <Image_Path>\n");
return -1;
}
Mat image;
image = imread( argv[1], 1 );
if ( !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.cpp )
target_link_libraries( DisplayImage ${OpenCV_LIBS} )然后,我尝试使用cmake生成可执行文件。制作
但我得到以下错误..。
clive@clive-Aspire-4755:~/Visual_Odometry/cpp/DisplayImage$ cmake .
-- The C compiler identification is GNU
-- The CXX compiler identification is GNU
-- Check for working C compiler: /usr/bin/gcc
-- Check for working C compiler: /usr/bin/gcc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Configuring done
-- Generating done
-- Build files have been written to: /home/clive/Visual_Odometry/cpp/DisplayImage
clive@clive-Aspire-4755:~/Visual_Odometry/cpp/DisplayImage$ make
Scanning dependencies of target DisplayImage
[100%] Building CXX object CMakeFiles/DisplayImage.dir/DisplayImage.cpp.o
/home/clive/Visual_Odometry/cpp/DisplayImage/DisplayImage.cpp: In function ‘int main(int, char**)’:
/home/clive/Visual_Odometry/cpp/DisplayImage/DisplayImage.cpp:8:5: error: ‘arg’ was not declared in this scope
/home/clive/Visual_Odometry/cpp/DisplayImage/DisplayImage.cpp:8:5: note: suggested alternative:
/usr/include/c++/4.6/complex:619:5: note: ‘std::arg’
/home/clive/Visual_Odometry/cpp/DisplayImage/DisplayImage.cpp:25:11: error: ‘waitkey’ was not declared in this scope
make[2]: *** [CMakeFiles/DisplayImage.dir/DisplayImage.cpp.o] Error 1
make[1]: *** [CMakeFiles/DisplayImage.dir/all] Error 2
make: *** [all] Error 2由于某些错误,无法创建DisplayImage可执行文件。有人能帮我一下吗?提前谢谢。
发布于 2014-10-18 15:11:29
对于那些面临这个问题的人,请尝试添加
#include <opencv2/highgui/highgui_c.h>到DisplayImage.cpp代码的顶部。然后再次编译和执行。希望它能成功!我现在就试着自己验证一下。
https://stackoverflow.com/questions/26440581
复制相似问题