DisplayImage.cpp错误使用OpenCV与gcc和CMake

时间:2014-02-11 05:11:16

标签: c++ opencv gcc

我在编译DisplayImage.cpp时遇到了问题,我已经按照教程here创建了一个cmake文件并生成了可执行文件,但是,当我用make编译问题时,它会显示以下错误:

Undefined symbols for architecture x86_64:
"cv::namedWindow(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, int)", referenced from:
_main in DisplayImage.cpp.o
"cv::imread(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, int)", referenced from:
_main in DisplayImage.cpp.o
"cv::imshow(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, cv::_InputArray const&)", referenced from:
_main in DisplayImage.cpp.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make[2]: *** [DisplayImage] Error 1
make[1]: *** [CMakeFiles/DisplayImage.dir/all] Error 2
make: *** [all] Error 2

我正在运行MacOS,任何人都可以帮忙!

由于

1 个答案:

答案 0 :(得分:0)

尝试添加

#include <opencv2/highgui/highgui_c.h>

到DisplayImage.cpp代码的顶部。然后再次编译并执行。 希望它有效!我现在只是自己尝试并验证了它。