I'm on a MacBook Pro, OSX Yosemite 10.10.4. I used homebrew to install gcc (to use as a c++ compiler) and opencv. Now when I run basic opencv example scripts, I'm getting an error I don't understand.
Undefined symbols for architecture x86_64:
"cv::Mat::deallocate()", referenced from:
cv::Mat::release() in c++_opencv_test-e26d2b.o
"cv::Mat::create(int, int const*, int)", referenced from:
cv::Mat::create(int, int, int) in c++_opencv_test-e26d2b.o
"cv::Mat::operator=(cv::Scalar_ const&)", referenced from:
cv::Mat::Mat(int, int, int, cv::Scalar_ const&) in c++_opencv_test-e26d2b.o
"cv::fastFree(void*)", referenced from:
cv::Mat::~Mat() in c++_opencv_test-e26d2b.o
"cv::Formatter::get(char const*)", referenced from:
cv::operator<<(std::__1::basic_ostream >&, cv::Mat const&) in c++_opencv_test-e26d2b.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
(sorry for the poor formatting, advice on that would be welcomed as well)
Here's the code I ran ...
#include <opencv2/core/core.hpp>
#include <iostream>
using namespace cv;
using namespace std;
int main( int argc, char** argv )
{
Mat img(2,2, CV_8UC3, Scalar(126,0,255));
cout << "img = \n " << img << "\n\n";
return 0;
}
I downloaded the normal OpenCV, not the 32-bit version, so I have no idea why I'm getting this error. I'm not very experienced in these command line issues. What should I try?
EDIT: Ok this command worked. My problem was definitely linking to the library.
g++ -ggdb 'pkg-config --cflags --libs /usr/local/opt/opencv3/lib/pkgconfig/opencv.pc' -stdlib=libstdc++ c++_opencv_test.cpp -o test
Apparently on OSX 10.9 and above, the compiler links by default to libc++ instead of libstdc++.
Anything I can do so I don't have to type out that long command each time I run something?