OPENCV 错误:未定义对"cvLoadImage"的引用
OPENCV error: undefined reference to "cvLoadImage"
我有两个文件:
test.cpp:
#include "highgui.h"
#include <cv.h>
int main( int argc, char** argv ) {
IplImage* img = cvLoadImage( argv[1] );
cvNamedWindow( "Example1", CV_WINDOW_AUTOSIZE );
cvShowImage( "Example1", img );
cvWaitKey(0);
cvReleaseImage( &img );
cvDestroyWindow( "Example1" );
}
CMakeLists.txt:
cmake_minimum_required(VERSION 2.8)
set(CMAKE_MODULE_PATH ${/home/jinder1s/Documents/project/opencv/FindOpenCV.make} )
project(hello)
Find_package (OpenCV REQUIRED)
if(OpenCV_FOUND)
add_executable (Hello test.cpp)
find_library(Opencv_lib
NAMES opencv_core opencv_highgui opencv_imgproc
PATHS /usr/local/lib)
endif()
这是我得到的模板。
jinder1s@jinder1s-lat-lap:~/Documents/project/opencv/tests$ cmake .
-- Configuring done
-- Generating done
-- Build files have been written to: /home/jinder1s/Documents/project/opencv/tests
jinder1s@jinder1s-lat-lap:~/Documents/project/opencv/tests$ make
Linking CXX executable Hello
CMakeFiles/Hello.dir/test.cpp.o: In function `main':
test.cpp:(.text+0x1d): undefined reference to `cvLoadImage'
test.cpp:(.text+0x35): undefined reference to `cvNamedWindow'
test.cpp:(.text+0x49): undefined reference to `cvShowImage'
test.cpp:(.text+0x55): undefined reference to `cvWaitKey'
test.cpp:(.text+0x61): undefined reference to `cvReleaseImage'
test.cpp:(.text+0x6d): undefined reference to `cvDestroyWindow'
collect2: error: ld returned 1 exit status
make[2]: *** [Hello] Error 1
make[1]: *** [CMakeFiles/Hello.dir/all] Error 2
make: *** [all] Error 2
我刚开始学习opencv,因为这是我的第一个代码,但我似乎无法让它发挥作用。我真的需要一些帮助。看不出我做错了什么。
在检查库是否可用后,您必须告诉cmake链接到库。
类似target_link_libraries( Hello ${OpenCV_LIBS} )
的东西就在您的endif()之前
请参阅http://www.cmake.org/cmake/help/cmake_tutorial.html了解如何使用CMake,以及http://docs.opencv.org/doc/tutorials/introduction/linux_gcc_cmake/linux_gcc_cmake.html用于带有openCV的CMake。
您可以通过键入"make VERBOSE=1"来检查链接器的调用方式。它有助于调试cmake文件。
我认为您需要在那里指定命名空间。因此,对于每个函数调用,要么在顶部执行using namespace cv;
,要么执行cv::function_name
。
此外,这看起来像OpenCV 1.x代码。你为什么不使用OpenCV2.x语法,而这么做是有原因的吗?2.x更加稳定和直观。例如,加载图像行在2.x中只是Mat img = imread(filename);
。对于2.x,您需要顶部的#include "opencv2/core/core.hpp"
和using namespace cv;
。
这份备忘单可能会有所帮助。
相关文章:
- 将对象数组的引用传递给函数
- 什么时候在C++中返回常量引用是个好主意
- 我想将一个对T类型的非常量左值引用绑定到一个T类型的临时值
- 何时在引用或唯一指针上使用移动语义
- 如何在c++中使用引用实现类似python的行为
- 编译C++时未定义的引用
- Ctypes wstring通过引用传递
- c++r值引用应用于函数指针
- 理解c++中的引用
- C++取消引用指针.为什么会发生变化
- 如何修复此错误:未定义对"距离(浮点数,浮点数,浮点数,浮点数,浮点数)"的引用
- 我的项目不会像"undefined reference to `grpc::g_core_codegen_interface'"那样使用未定义的引用错误进行编译
- C++Boost Asio Pool线程,带有lambda函数和传递引用变量
- 强制转换为引用类型
- 引用一个已擦除类型(void*)的指针
- 向量元素的引用地址与它所指向的向量元素的地址不同.为什么
- 具有默认值的引用获取函数
- 如何使用基类指针引用派生类成员
- 使用取消引用的指针的多态性会产生意外的结果.为什么?
- OPENCV 错误:未定义对"cvLoadImage"的引用