【发布时间】:2017-07-20 17:41:55
【问题描述】:
这是一个代码。当我尝试在 Eclipse 中构建它时,它显示“imread”并且几乎所有函数都没有在范围内声明。
#include <cv.h>
#include <opencv2/opencv.hpp>
#include <highgui.h>
using namespace cv;
int main( int argc, char** argv )
{
Mat image;
image = imread( "download.jpg",0 );
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;
}
错误列表如下所示
Description Resource Path Location Type
make: *** [src/DisplayImage1.o] Error 1 DisplayImage C/C++ Problem
make: *** [display] Error 1 display C/C++ Problem
‘namedWindow’ was not declared in this scope DisplayImage1.cpp /DisplayImage/src line 23 C/C++ Problem
‘imread’ was not declared in this scope DisplayImage1.cpp /DisplayImage/src line 15 C/C++ Problem
‘waitKey’ was not declared in this scope DisplayImage1.cpp /DisplayImage/src line 26 C/C++ Problem
‘imshow’ was not declared in this scope DisplayImage1.cpp /DisplayImage/src line 24 C/C++ Problem
undefined reference to `cvRound' display line 929, external location: /usr/local/include/opencv2/core/types_c.h C/C++ Problem
undefined reference to `cvRound' display line 930, external location: /usr/local/include/opencv2/core/types_c.h C/C++ Problem
undefined reference to `cvFree_' display line 305, external location: /usr/local/include/opencv2/core/core_c.h C/C++ Problem
undefined reference to `cvFree_' display line 313, external location: /usr/local/include/opencv2/core/core_c.h C/C++ Problem
undefined reference to `cvGetRows' display line 382, external location: /usr/local/include/opencv2/core/core_c.h C/C++ Problem
undefined reference to `cvGetCols' display line 408, external location: /usr/local/include/opencv2/core/core_c.h C/C++ Problem
undefined reference to `cvReleaseMat' display line 477, external location: /usr/local/include/opencv2/core/core_c.h C/C++ Problem
不知道该怎么办。任何的想法 ??我正在 eclipse 中运行代码。将 opencv 库加载到它。我使用 ubuntu。 任何帮助都会被应用
控制台消息:
make all
Building file: ../src/DisplayImage.cpp
Invoking: Cross G++ Compiler
g++ -I/usr/local/include/opencv -O0 -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF"src/DisplayImage.d" -MT"src/DisplayImage.d" -o "src/DisplayImage.o" "../src/DisplayImage.cpp"
Finished building: ../src/DisplayImage.cpp
Building file: ../src/DisplayImage1.cpp
Invoking: Cross G++ Compiler
g++ -I/usr/local/include/opencv -O0 -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF"src/DisplayImage1.d" -MT"src/DisplayImage1.d" -o "src/DisplayImage1.o" "../src/DisplayImage1.cpp"
../src/DisplayImage1.cpp: In function ‘int main(int, char**)’:
../src/DisplayImage1.cpp:15:30: error: ‘imread’ was not declared in this scope
image = imread( argv[1], 1 );
^
../src/DisplayImage1.cpp:23:52: error: ‘namedWindow’ was not declared in this scope
namedWindow( "Display Image", CV_WINDOW_AUTOSIZE );
^
../src/DisplayImage1.cpp:24:34: error: ‘imshow’ was not declared in this scope
imshow( "Display Image", image );
^
../src/DisplayImage1.cpp:26:12: error: ‘waitKey’ was not declared in this scope
waitKey(0);
^
make: *** [src/DisplayImage1.o] Error 1
【问题讨论】:
-
从“问题”选项卡切换到“控制台”选项卡。您会发现更好的错误消息,并且您会发现用于构建项目的命令。检查链接器命令行以确保您正在链接 opencv 库。如果您不确定,请编辑您的问题并粘贴到控制台选项卡的内容中。
-
附录:问题列表中的前几项是由 Eclipse 自己生成的。您可以通过重新索引项目来解决它们。在 Project Explorer 窗格中,右键单击项目并从弹出菜单中选择 Index->Rebuild。
-
请立即查看@user4581301
-
我正在链接正确的库,这段代码在没有 Eclipse 的情况下运行
-
哈,你说得对。我是倒着读的。我很抱歉。未定义的引用是虚假的或陈旧的。