I have a very basic program to test that OpenCV works.
#include <opencv2/opencv.hpp>
int main() {
cv::namedWindow("Window", CV_WINDOW_AUTOSIZE);
cv::VideoCapture video_capture;
video_capture.open(0);
while (true) {
cv::Mat image;
video_capture.read(image);
cv::imshow("Window", image);
if (cv::waitKey(1) == 27) {
break;
}
}
return 0;
}
And a CMakeLists.txt file that finds OpenCV like so:
find_package(OpenCV REQUIRED)
...
target_link_libraries(Project ${OpenCV_LIBS})
This works on Mac OSX 10.10 using OpenCV 2.4.10 and clang 602.0.49, but If I try to use gcc 5.1 by putting set(CMAKE_CXX_COMPILER /usr/gcc-5.1.0/bin/g++-5.1.0)
in my CMakeLists.txt, I get the following error:
Undefined symbols for architecture x86_64:
"cv::namedWindow(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, int)", referenced from:
_main in main.cpp.o
"cv::imshow(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, cv::_InputArray const&)", referenced from:
_main in main.cpp.o
What's the problem and how do I fix it?