简体   繁体   中英

OpenCV for iOS - Linking Libraries in Xcode

As part of a team project I intend to implement obstacle detection for a robot using open cv. I am now at a point where I have functional code that runs on OS X and uses my laptop camera to detect obstacles approaching it. However the robot runs iOS (it is an iPad at heart) and thus requires me to build for iOS. Obviously the linker now doesn't accept the OS X library files, because of architecture mismatches. So far it is set up as follows:
1. /usr/local/lib added to Library Search Paths
2. /usr/local/include added to Header Search Paths
3. c++ language dialect changed to C++11
4. Libraries added to Other Linker Flags ( -lopencv_calib3d etc.)
5. Valid Architectures set to i386 , x86_64

In order to perform the necessary modifications for iOS I first of all changed the valid architectures to armv7 , armv7s , and arm64 . Then I attempted to follow the instructions on OpenCV:Installation in iOS , asking me to execute the opencv/platforms/ios/build_framework.py script. This built a framework file and a folder build . I added the framework file to my Xcode project via Build Phases -> Link Binary With Libraries. According to the python script's readme "The script builds OpenCV.framework for iOS. The built framework is universal, it can be used to build app and run it on either iOS simulator or real device." However when I try to build the product for iOS simulator (amongst others), I get uncountable Undefined symbols for architecture x86_64 linker errors. As far as I am aware there is nothing else to the installation instructions linked above though.

Am I missing something here? Adjusting header/library search paths to include either nothing or the OS X OpenCV library files from /usr/local/lib was to no avail. My intuition is that is has something to do with the folder build created by the python script alongside the opencv2.framework file. The contents of build are the folders:
iPhoneOS-arm64
iPhoneOS-armv7
iPhoneOS-armv7s
iPhoneSimulator-i386
iPhoneSimulator-x86_64

These in turn are comprised of:

在此处输入图片说明

Do I need to link any part of these folders into my project?

I am grateful for any advice.

Warm regards,
Mark

EDIT: Here are the linker errors I get when compiling for iOS simulator. When compiling for another architecture x (for example armv7) I get the exact same errors, differing only in the line Undefined symbols for architecture x .

Ld /Users/schuegrafm/Documents/SS15/CooperativeRobots/SDK/DoubleBasicHelloWorld/build/Double_IRL.build/Debug-iphonesimulator/Double_IRL.build/Objects-normal/x86_64/Double_IRL normal x86_64 cd "/Users/schuegrafm/Documents/SS15/CooperativeRobots/Double IRL Project/Double_IRL" export IPHONEOS_DEPLOYMENT_TARGET=6.0 export PATH="/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin:/Applications/Xcode.app/Contents/Developer/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin" /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang++ -arch x86_64 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator8.4.sdk -L/Users/schuegrafm/Documents/SS15/CooperativeRobots/SDK/DoubleBasicHelloWorld/build/Debug-iphonesimulator -F/Users/schuegrafm/Documents/SS15/CooperativeRobots/SDK/DoubleBasicHelloWorld/build/Debug-iphonesimulator -F/Users/schuegrafm/Documents/SS15/CooperativeRo bots/Double\\ IRL\\ Project/Double_IRL/.. -F/Users/schuegrafm/Documents/Programming_Tools/ios -filelist /Users/schuegrafm/Documents/SS15/CooperativeRobots/SDK/DoubleBasicHelloWorld/build/Double_IRL.build/Debug-iphonesimulator/Double_IRL.build/Objects-normal/x86_64/Double_IRL.LinkFileList -Xlinker -objc_abi_version -Xlinker 2 -fobjc-arc -fobjc-link-runtime -Xlinker -no_implicit_dylibs -stdlib=libc++ -mios-simulator-version-min=6.0 -framework opencv2 -framework DoubleControlSDK -framework ExternalAccessory -framework UIKit -framework Foundation -framework CoreGraphics -Xlinker -dependency_info -Xlinker /Users/schuegrafm/Documents/SS15/CooperativeRobots/SDK/DoubleBasicHelloWorld/build/Double_IRL.build/Debug-iphonesimulator/Double_IRL.build/Objects-normal/x86_64/Double_IRL_dependency_info.dat -o /Users/schuegrafm/Documents/SS15/CooperativeRobots/SDK/DoubleBasicHelloWorld/build/Double_IRL.build/Debug-iphonesimulator/Double_IRL.build/Objects-normal/x86_64/Double_IRL

Undefined symbols for architecture x86_64:
"_AVCaptureSessionPresetMedium", referenced from: CvCaptureCAM::startCaptureDevice(int) in opencv2(cap_avfoundation.o) "_AVFileType3GPP", referenced from: CvVideoWriter_AVFoundation::CvVideoWriter_AVFoundation(char const*, int, double, CvSize, int) in opencv2(cap_avfoundation.o)
"_AVFileTypeAppleM4V", referenced from: CvVideoWriter_AVFoundation::CvVideoWriter_AVFoundation(char const*, int, double, CvSize, int) in opencv2(cap_avfoundation.o)
"_AVFileTypeMPEG4", referenced from: CvVideoWriter_AVFoundation::CvVideoWriter_AVFoundation(char const*, int, double, CvSize, int) in opencv2(cap_avfoundation.o)
"_AVFileTypeQuickTimeMovie", referenced from: CvVideoWriter_AVFoundation::CvVideoWriter_AVFoundation(char const*, int, double, CvSize, int) in opencv2(cap_avfoundation.o)
"_AVMediaTypeVideo", referenced from: CvCaptureCAM::startCaptureDevice(int) in opencv2(cap_avfoundation.o) CvCaptureFile::CvCaptureFile(char const*) in opencv2(cap_avfoundation.o) CvVideoWriter_AVFoundation::CvVideoWriter_AVFoundation(char const*, int, double, CvSize, int) in opencv2(cap_avfoundation.o)
"_AVVideoCodecH264", referenced from: CvVideoWriter_AVFoundation::CvVideoWriter_AVFoundation(char const*, int, double, CvSize, int) in opencv2(cap_avfoundation.o)
"_AVVideoCodecJPEG", referenced from: CvVideoWriter_AVFoundation::CvVideoWriter_AVFoundation(char const*, int, double, CvSize, int) in opencv2(cap_avfoundation.o)
"_AVVideoCodecKey", referenced from: CvVideoWriter_AVFoundation::CvVideoWriter_AVFoundation(char const*, int, double, CvSize, int) in opencv2(cap_avfoundation.o)
"_AVVideoHeightKey", referenced from: CvVideoWriter_AVFoundation::CvVideoWriter_AVFoundation(char const*, int, double, CvSize, int) in opencv2(cap_avfoundation.o)
"_AVVideoWidthKey", referenced from: CvVideoWriter_AVFoundation::CvVideoWriter_AVFoundation(char const*, int, double, CvSize, int) in opencv2(cap_avfoundation.o)
"_CMSampleBufferGetImageBuffer", referenced from: -[CaptureDelegate captureOutput:didOutputSampleBuffer:fromConnection:] in opencv2(cap_avfoundation.o) CvCaptureFile::retrieveFramePixelBuffer() in opencv2(cap_avfoundation.o) "_CMSampleBufferInvalidate", referenced from: CvCaptureFile::retrieveFramePixelBuffer() in opencv2(cap_avfoundation.o) "_CMTimeMake", referenced from: CvCaptureCAM::startCaptureDevice(int) in opencv2(cap_avfoundation.o) CvVideoWriter_AVFoundation::writeFrame(_IplImage const*) in opencv2(cap_avfoundation.o)
"_CMVideoFormatDescriptionGetPresentationDimensions", referenced from: CvCaptureCAM::getProperty(int) const in opencv2(cap_avfoundation.o) "_CVBufferRelease", referenced from: -[CaptureDelegate captureOutput:didOutputSampleBuffer:fromConnection:] in opencv2(cap_avfoundation.o) -[CaptureDelegate updateImage] in opencv2(cap_avfoundation.o) CvCaptureFile::retrieveFramePixelBuffer() in opencv2(cap_avfoundation.o) "_CVBufferRetain", referenced from: -[CaptureDelegate captureOutput:didOutputSampleBuffer:fromConnection:] in opencv2(cap_avfoundation.o) -[CaptureDelegate updateImage] in opencv2(cap_avfoundation.o) CvCaptureFile::retrieveFramePixelBuffer() in opencv2(cap_avfoundation.o) "_CVPixelBufferCreateWithBytes", referenced from: CvVideoWriter_AVFoundation::writeFrame(_IplImage const*) in opencv2(cap_avfoundation.o) "_CVPixelBufferGetBaseAddress", referenced from: -[CaptureDelegate updateImage] in opencv2(cap_avfoundation.o) CvCaptureFile::retrieveFramePixelBuffer() in opencv2(cap_avfounda tion.o) "_CVPixelBufferGetBytesPerRow", referenced from: -[CaptureDelegate updateImage] in opencv2(cap_avfoundation.o) CvCaptureFile::retrieveFramePixelBuffer() in opencv2(cap_avfoundation.o) "_CVPixelBufferGetHeight", referenced from: -[CaptureDelegate updateImage] in opencv2(cap_avfoundation.o) CvCaptureFile::retrieveFramePixelBuffer() in opencv2(cap_avfoundation.o) "_CVPixelBufferGetWidth", referenced from: -[CaptureDelegate updateImage] in opencv2(cap_avfoundation.o) CvCaptureFile::retrieveFramePixelBuffer() in opencv2(cap_avfoundation.o) "_CVPixelBufferLockBaseAddress", referenced from: -[CaptureDelegate updateImage] in opencv2(cap_avfoundation.o) CvCaptureFile::retrieveFramePixelBuffer() in opencv2(cap_avfoundation.o) "_CVPixelBufferRelease", referenced from: CvVideoWriter_AVFoundation::writeFrame(_IplImage const*) in opencv2(cap_avfoundation.o) "_CVPixelBufferUnlockBaseAddress", referenced from: -[CaptureDelegate updateImage] in opencv2(cap_avfoundation.o) CvCaptureFile::retriev eFramePixelBuffer() in opencv2(cap_avfoundation.o) "_OBJC_CLASS_$_AVAssetReader", referenced from: objc-class-ref in opencv2(cap_avfoundation.o) "_OBJC_CLASS_$_AVAssetReaderTrackOutput", referenced from: objc-class-ref in opencv2(cap_avfoundation.o) "_OBJC_CLASS_$_AVAssetWriter", referenced from: objc-class-ref in opencv2(cap_avfoundation.o) "_OBJC_CLASS_$_AVAssetWriterInput", referenced from: objc-class-ref in opencv2(cap_avfoundation.o) "_OBJC_CLASS_$_AVAssetWriterInputPixelBufferAdaptor", referenced from: objc-class-ref in opencv2(cap_avfoundation.o) "_OBJC_CLASS_$_AVCaptureDevice", referenced from: objc-class-ref in opencv2(cap_avfoundation.o) "_OBJC_CLASS_$_AVCaptureDeviceInput", referenced from: objc-class-ref in opencv2(cap_avfoundation.o) "_OBJC_CLASS_$_AVCaptureSession", referenced from: objc-class-ref in opencv2(cap_avfoundation.o) "_OBJC_CLASS_$_AVCaptureVideoDataOutput", referenced from: objc-class-ref in opencv2(cap_avfoundation.o) "_OBJC_CLASS_$_AVURLAsset", referenced fr om: objc-class-ref in opencv2(cap_avfoundation.o) "_kCMTimeZero", referenced from: CvVideoWriter_AVFoundation::CvVideoWriter_AVFoundation(char const*, int, double, CvSize, int) in opencv2(cap_avfoundation.o)
"_kCVPixelBufferHeightKey", referenced from: CvCaptureCAM::startCaptureDevice(int) in opencv2(cap_avfoundation.o) CvCaptureCAM::setWidthHeight() in opencv2(cap_avfoundation.o) "_kCVPixelBufferPixelFormatTypeKey", referenced from: CvCaptureCAM::startCaptureDevice(int) in opencv2(cap_avfoundation.o) CvCaptureCAM::setWidthHeight() in opencv2(cap_avfoundation.o) CvCaptureFile::CvCaptureFile(char const*) in opencv2(cap_avfoundation.o) "_kCVPixelBufferWidthKey", referenced from: CvCaptureCAM::startCaptureDevice(int) in opencv2(cap_avfoundation.o) CvCaptureCAM::setWidthHeight() in opencv2(cap_avfoundation.o) ld: symbol(s) not found for architecture x86_64

EDIT2: Errors left after adding AV foundation framework.

Ld /Users/schuegrafm/Documents/SS15/CooperativeRobots/SDK/DoubleBasicHelloWorld/build/Double_IRL.build/Debug-iphonesimulator/Double_IRL.build/Objects-normal/x86_64/Double_IRL normal x86_64 cd "/Users/schuegrafm/Documents/SS15/CooperativeRobots/Double IRL Project/Double_IRL" export IPHONEOS_DEPLOYMENT_TARGET=6.0 export PATH="/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin:/Applications/Xcode.app/Contents/Developer/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin" /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang++ -arch x86_64 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator8.4.sdk -L/Users/schuegrafm/Documents/SS15/CooperativeRobots/SDK/DoubleBasicHelloWorld/build/Debug-iphonesimulator -F/Users/schuegrafm/Documents/SS15/CooperativeRobots/SDK/DoubleBasicHelloWorld/build/Debug-iphonesimulator -F/Users/schuegrafm/Documents/SS15/CooperativeRo bots/Double\\ IRL\\ Project/Double_IRL/.. -F/Users/schuegrafm/Documents/Programming_Tools/ios -filelist /Users/schuegrafm/Documents/SS15/CooperativeRobots/SDK/DoubleBasicHelloWorld/build/Double_IRL.build/Debug-iphonesimulator/Double_IRL.build/Objects-normal/x86_64/Double_IRL.LinkFileList -Xlinker -objc_abi_version -Xlinker 2 -fobjc-arc -fobjc-link-runtime -Xlinker -no_implicit_dylibs -stdlib=libc++ -mios-simulator-version-min=6.0 -framework AVFoundation -framework opencv2 -framework DoubleControlSDK -framework ExternalAccessory -framework UIKit -framework Foundation -framework CoreGraphics -Xlinker -dependency_info -Xlinker /Users/schuegrafm/Documents/SS15/CooperativeRobots/SDK/DoubleBasicHelloWorld/build/Double_IRL.build/Debug-iphonesimulator/Double_IRL.build/Objects-normal/x86_64/Double_IRL_dependency_info.dat -o /Users/schuegrafm/Documents/SS15/CooperativeRobots/SDK/DoubleBasicHelloWorld/build/Double_IRL.build/Debug-iphonesimulator/Double_IRL.build/Objects-normal/x86_64/Double_IRL

Undefined symbols for architecture x86_64:
"_CMSampleBufferGetImageBuffer", referenced from: -[CaptureDelegate captureOutput:didOutputSampleBuffer:fromConnection:] in opencv2(cap_avfoundation.o) CvCaptureFile::retrieveFramePixelBuffer() in opencv2(cap_avfoundation.o) "_CMSampleBufferInvalidate", referenced from: CvCaptureFile::retrieveFramePixelBuffer() in opencv2(cap_avfoundation.o) "_CMTimeMake", referenced from: CvCaptureCAM::startCaptureDevice(int) in opencv2(cap_avfoundation.o) CvVideoWriter_AVFoundation::writeFrame(_IplImage const*) in opencv2(cap_avfoundation.o)
"_CMVideoFormatDescriptionGetPresentationDimensions", referenced from: CvCaptureCAM::getProperty(int) const in opencv2(cap_avfoundation.o) "_CVBufferRelease", referenced from: -[CaptureDelegate captureOutput:didOutputSampleBuffer:fromConnection:] in opencv2(cap_avfoundation.o) -[CaptureDelegate updateImage] in opencv2(cap_avfoundation.o) CvCaptureFile::retrieveFramePixelBuffer() in opencv2(cap_avfoundation.o) "_CVBufferRetain", referenced from: -[CaptureDelegate captureOutput:didOutputSampleBuffer:fromConnection:] in opencv2(cap_avfoundation.o) -[CaptureDelegate updateImage] in opencv2(cap_avfoundation.o) CvCaptureFile::retrieveFramePixelBuffer() in opencv2(cap_avfoundation.o) "_CVPixelBufferCreateWithBytes", referenced from: CvVideoWriter_AVFoundation::writeFrame(_IplImage const*) in opencv2(cap_avfoundation.o) "_CVPixelBufferGetBaseAddress", referenced from: -[CaptureDelegate updateImage] in opencv2(cap_avfoundation.o) CvCaptureFile::retrieveFramePixelBuffer() in opencv2(cap_avfounda tion.o) "_CVPixelBufferGetBytesPerRow", referenced from: -[CaptureDelegate updateImage] in opencv2(cap_avfoundation.o) CvCaptureFile::retrieveFramePixelBuffer() in opencv2(cap_avfoundation.o) "_CVPixelBufferGetHeight", referenced from: -[CaptureDelegate updateImage] in opencv2(cap_avfoundation.o) CvCaptureFile::retrieveFramePixelBuffer() in opencv2(cap_avfoundation.o) "_CVPixelBufferGetWidth", referenced from: -[CaptureDelegate updateImage] in opencv2(cap_avfoundation.o) CvCaptureFile::retrieveFramePixelBuffer() in opencv2(cap_avfoundation.o) "_CVPixelBufferLockBaseAddress", referenced from: -[CaptureDelegate updateImage] in opencv2(cap_avfoundation.o) CvCaptureFile::retrieveFramePixelBuffer() in opencv2(cap_avfoundation.o) "_CVPixelBufferRelease", referenced from: CvVideoWriter_AVFoundation::writeFrame(_IplImage const*) in opencv2(cap_avfoundation.o) "_CVPixelBufferUnlockBaseAddress", referenced from: -[CaptureDelegate updateImage] in opencv2(cap_avfoundation.o) CvCaptureFile::retriev eFramePixelBuffer() in opencv2(cap_avfoundation.o) "_kCMTimeZero", referenced from: CvVideoWriter_AVFoundation::CvVideoWriter_AVFoundation(char const*, int, double, CvSize, int) in opencv2(cap_avfoundation.o)
"_kCVPixelBufferHeightKey", referenced from: CvCaptureCAM::startCaptureDevice(int) in opencv2(cap_avfoundation.o) CvCaptureCAM::setWidthHeight() in opencv2(cap_avfoundation.o) "_kCVPixelBufferPixelFormatTypeKey", referenced from: CvCaptureCAM::startCaptureDevice(int) in opencv2(cap_avfoundation.o) CvCaptureCAM::setWidthHeight() in opencv2(cap_avfoundation.o) CvCaptureFile::CvCaptureFile(char const*) in opencv2(cap_avfoundation.o) "_kCVPixelBufferWidthKey", referenced from: CvCaptureCAM::startCaptureDevice(int) in opencv2(cap_avfoundation.o) CvCaptureCAM::setWidthHeight() in opencv2(cap_avfoundation.o) ld: symbol(s) not found for architecture x86_64 clang: error: linker command failed with exit code 1 (use -v to see invocation)

EDIT3: Remaining 14 errors.

Undefined symbols for architecture x86_64: "_CVBufferRelease", referenced from: -[CaptureDelegate captureOutput:didOutputSampleBuffer:fromConnection:] in opencv2(cap_avfoundation.o) -[CaptureDelegate updateImage] in opencv2(cap_avfoundation.o) CvCaptureFile::retrieveFramePixelBuffer() in opencv2(cap_avfoundation.o) "_CVBufferRetain", referenced from: -[CaptureDelegate captureOutput:didOutputSampleBuffer:fromConnection:] in opencv2(cap_avfoundation.o) -[CaptureDelegate updateImage] in opencv2(cap_avfoundation.o) CvCaptureFile::retrieveFramePixelBuffer() in opencv2(cap_avfoundation.o) "_CVPixelBufferCreateWithBytes", referenced from: CvVideoWriter_AVFoundation::writeFrame(_IplImage const*) in opencv2(cap_avfoundation.o) "_CVPixelBufferGetBaseAddress", referenced from: -[CaptureDelegate updateImage] in opencv2(cap_avfoundation.o) CvCaptureFile::retrieveFramePixelBuffer() in opencv2(cap_avfoundation.o) "_CVPixelBufferGetBytesPerRow", referenced from: -[CaptureDelegate updateImage] in openc v2(cap_avfoundation.o) CvCaptureFile::retrieveFramePixelBuffer() in opencv2(cap_avfoundation.o) "_CVPixelBufferGetHeight", referenced from: -[CaptureDelegate updateImage] in opencv2(cap_avfoundation.o) CvCaptureFile::retrieveFramePixelBuffer() in opencv2(cap_avfoundation.o) "_CVPixelBufferGetWidth", referenced from: -[CaptureDelegate updateImage] in opencv2(cap_avfoundation.o) CvCaptureFile::retrieveFramePixelBuffer() in opencv2(cap_avfoundation.o) "_CVPixelBufferLockBaseAddress", referenced from: -[CaptureDelegate updateImage] in opencv2(cap_avfoundation.o) CvCaptureFile::retrieveFramePixelBuffer() in opencv2(cap_avfoundation.o) "_CVPixelBufferRelease", referenced from: CvVideoWriter_AVFoundation::writeFrame(_IplImage const*) in opencv2(cap_avfoundation.o) "_CVPixelBufferUnlockBaseAddress", referenced from: -[CaptureDelegate updateImage] in opencv2(cap_avfoundation.o) CvCaptureFile::retrieveFramePixelBuffer() in opencv2(cap_avfoundation.o) "_kCVPixelBufferHeightKey", referenced from: CvCaptureCAM::startCaptureDevice(int) in opencv2(cap_avfoundation.o) CvCaptureCAM::setWidthHeight() in opencv2(cap_avfoundation.o) "_kCVPixelBufferPixelFormatTypeKey", referenced from: CvCaptureCAM::startCaptureDevice(int) in opencv2(cap_avfoundation.o) CvCaptureCAM::setWidthHeight() in opencv2(cap_avfoundation.o) CvCaptureFile::CvCaptureFile(char const*) in opencv2(cap_avfoundation.o) "_kCVPixelBufferWidthKey", referenced from: CvCaptureCAM::startCaptureDevice(int) in opencv2(cap_avfoundation.o) CvCaptureCAM::setWidthHeight() in opencv2(cap_avfoundation.o) ld: symbol(s) not found for architecture x86_64 clang: error: linker command failed with exit code 1 (use -v to see invocation)

Take a look on tutorials for iOS on official OpenCV site. You will there information about dependencies.

To import OpenCV 3 into your Xcode 8 project:

  1. Install 'OpenCV2' with Cocoapods (it says '2', but it's still version 3). Don't install the 'devel' build.

  2. Open your project in the workspace Cocoapods created for you — not the project file you created — and append every implementation file that uses OpenCV with .mm (versus .m). You'll get strange error messages if you don't.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM