I have a problem linking OpenCV in Xcode. I installed OpenCV using brew:
brew tap homebrew/science
sudo brew install opencv
I started a new Xcode commandline project, added /usr/local/lib
and /usr/local/include
to library and header search path.
I also added the output of pkg-config --libs opencv
to other linker options
.
But when I try to compile this small sample program:
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
int main(int argc, char *argv[])
{
cv::Mat test;
cv::namedWindow( "Display window", CV_WINDOW_AUTOSIZE );// Create a window for display.
cv::waitKey(0); // Wait for a keystroke in the window
return 0;
}
i get the following linker error:
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 main.o
ld: symbol(s) not found for architecture x86_64
But I am able to compile the program on the command line using
g++ `pkg-config --cflags --libs opencv` prog.cpp
So I think the problem is the way Xcode is set up. But I am not able to determine what exactly is different between the way Xcode compiles and my commandline argument.
Does anyone know the reason for this error or has an idea what I could try to investigate the problem?
In Xcode create a new group inside your project, right click it, choose Add Files to Project, navigate to the /usr/local/lib
folder and add the following basic libraries:
libopencv_core.dylib, libopencv_ml.dylib, libopencv_video.dylib
In previous versions of OpenCV the library names could be:
libcxcore.dylib, libcvaux.dylib, libcv.dylib, libhighgui.dylib, libml.dylib
(The libraries may be in another path depending on the method you used to install OpenCV on your Mac.)
Edit:
The above lines should not be necessary if you are including the dynamic libraries in the linking phase as the OP explains.
Select your project, go to the Build Settings tab, filter by c++ standard library, and set this parameter to libstdc++ (GNU C++ standard library).
I've set the Build Settings -> c++ standard library to Compiler Default. The errors disappeared.
I had to add the following libraries (build phases -> link binary with libraries) so OpenCV would build:
Ref: http://docs.opencv.org/doc/tutorials/ios/video_processing/video_processing.html#opencviosvideoprocessing
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With