无法将OpenCV代码与gcc链接

时间:2015-08-21 20:18:55

标签: c++ opencv gcc linker makefile

我有这个非常简单的C ++文件

#include <opencv2/opencv.hpp>
int main(int argc, const char *argv[])
{
   using namespace cv;
   Mat m = imread("image.jpg");
   imwrite("image2.jpg",m);
   return 0;
}

我的CMakeLists.txt

set(CMAKE_CXX_COMPILER g++)
set(CMAKE_C_COMPILER gcc)
find_package(OpenCV REQUIRED)
if(OpenCV_FOUND)
   add_executable(foobar test.cpp)
   include_directories(${OpenCV_INCLUDE_DIRS})
   target_link_libraries(foobar ${OpenCV_LIBS})
endif(OpenCV_FOUND)

OpenCV包含在/opt/local/include/opt/local/lib中的库(MacPorts安装,但我尝试使用/usr/local中的另一个版本手动编译,结果相同)。我收到链接错误

Undefined symbols for architecture x86_64:
  "cv::imwrite(cv::String const&, cv::_InputArray const&, std::vector<int, std::allocator<int> > const&)", referenced from:
      _main in test.o

现在我可以切换到clang,但我想尝试OpenMP,所以gcc应该是gcc。此外,它让我烦恼,我不知道出了什么问题。是否与编译OpenCV的方式有关(使用clangforeach)?

0 个答案:

没有答案