问题
I successfully built OpenCV on my Mac but couldn't compile a simple OpenCV project with XCode.
I added libopencv_core, libopencv_highgui and libopencv_imgproc to a file group in project.
Here is the linker output:
/Users/petilodie/Library/Developer/Xcode/DerivedData/opencv_test-fylvojzfgmnpmycaxkpiajicbmii/Build/Products/Debug/opencv_test normal x86_64
cd /Users/petilodie/Projects/Test/opencv_test
setenv MACOSX_DEPLOYMENT_TARGET 10.8
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang++ -arch x86_64 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.8.sdk -L/Users/petilodie/Library/Developer/Xcode/DerivedData/opencv_test-fylvojzfgmnpmycaxkpiajicbmii/Build/Products/Debug -F/Users/petilodie/Library/Developer/Xcode/DerivedData/opencv_test-fylvojzfgmnpmycaxkpiajicbmii/Build/Products/Debug -filelist /Users/petilodie/Library/Developer/Xcode/DerivedData/opencv_test-fylvojzfgmnpmycaxkpiajicbmii/Build/Intermediates/opencv_test.build/Debug/opencv_test.build/Objects-normal/x86_64/opencv_test.LinkFileList -mmacosx-version-min=10.8 -o /Users/petilodie/Library/Developer/Xcode/DerivedData/opencv_test-fylvojzfgmnpmycaxkpiajicbmii/Build/Products/Debug/opencv_test
Undefined symbols for architecture x86_64:
"_cvDestroyWindow", referenced from:
_main in main.o
"_cvLoadImage", referenced from:
_main in main.o
"_cvNamedWindow", referenced from:
_main in main.o
"_cvReleaseImage", referenced from:
_main in main.o
"_cvShowImage", referenced from:
_main in main.o
"_cvWaitKey", referenced from:
_main in main.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Here is the code in main.cpp:
#include <iostream>
#include "opencv2/imgproc/imgproc.hpp"
#include "opencv2/highgui/highgui.hpp"
int main(int argc, const char * argv[])
{
IplImage* img = cvLoadImage( argv[1] );
cvNamedWindow( "Example1", CV_WINDOW_AUTOSIZE );
cvShowImage( "Example1", img );
cvWaitKey(0);
cvReleaseImage( &img );
cvDestroyWindow( "Example1" );
}
So, what's the problem here?
回答1:
You need to link the libraries to your binary:
来源:https://stackoverflow.com/questions/11811378/unable-to-compile-opencv-project-with-xcode-4