使用依赖子项目时 Xcode 中的链接问题
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5045299/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Linking problem in Xcode when using a dependent subproject
提问by GorillaPatch
I am using Xcode to write an iPhone project and I use an external library. I added the Xcode project file to the parent target and adjusted the header search path and set it as a direct dependency in the parent's build target.
我正在使用 Xcode 编写一个 iPhone 项目,并使用一个外部库。我将 Xcode 项目文件添加到父目标并调整头搜索路径并将其设置为父构建目标中的直接依赖项。
Now the strange thing happens: I can open the library and compile it without problems. The library links to some frameworks e.g. AVFoundation.framework
.
现在奇怪的事情发生了:我可以毫无问题地打开库并编译它。该库链接到一些框架,例如AVFoundation.framework
.
I clean the target and start building the parent project. In my build results I see that it builds the library, but then the linking fails with these error messages:
我清理目标并开始构建父项目。在我的构建结果中,我看到它构建了库,但是链接失败并显示以下错误消息:
Undefined symbols:
"_AVCaptureSessionPresetMedium", referenced from:
_AVCaptureSessionPresetMedium$non_lazy_ptr in libZXingWidget.a(ZXingWidgetController.o)
(maybe you meant: _AVCaptureSessionPresetMedium$non_lazy_ptr)
"_CVPixelBufferGetHeight", referenced from:
-[ZXingWidgetController captureOutput:didOutputSampleBuffer:fromConnection:] in libZXingWidget.a(ZXingWidgetController.o)
"_CVPixelBufferLockBaseAddress", referenced from:
-[ZXingWidgetController captureOutput:didOutputSampleBuffer:fromConnection:] in libZXingWidget.a(ZXingWidgetController.o)
"_AudioServicesPlaySystemSound", referenced from:
-[ZXingWidgetController presentResultForString:] in libZXingWidget.a(ZXingWidgetController.o)
"_AudioServicesCreateSystemSoundID", referenced from:
-[ZXingWidgetController viewWillAppear:] in libZXingWidget.a(ZXingWidgetController.o)
"_CVPixelBufferUnlockBaseAddress", referenced from:
-[ZXingWidgetController captureOutput:didOutputSampleBuffer:fromConnection:] in libZXingWidget.a(ZXingWidgetController.o)
"_CVPixelBufferGetBaseAddress", referenced from:
-[ZXingWidgetController captureOutput:didOutputSampleBuffer:fromConnection:] in libZXingWidget.a(ZXingWidgetController.o)
"_CVPixelBufferGetBytesPerRow", referenced from:
-[ZXingWidgetController captureOutput:didOutputSampleBuffer:fromConnection:] in libZXingWidget.a(ZXingWidgetController.o)
"_iconv_close", referenced from:
zxing::qrcode::DecodedBitStreamParser::append(std::basic_string<char, std::char_traits<char>, std::allocator<char> >&, unsigned char const*, unsigned long, char const*)in libZXingWidget.a(DecodedBitStreamParser-64E27B33E79CBC52.o)
zxing::qrcode::DecodedBitStreamParser::append(std::basic_string<char, std::char_traits<char>, std::allocator<char> >&, unsigned char const*, unsigned long, char const*)in libZXingWidget.a(DecodedBitStreamParser-64E27B33E79CBC52.o)
"_OBJC_CLASS_$_AVCaptureVideoPreviewLayer", referenced from:
objc-class-ref-to-AVCaptureVideoPreviewLayer in libZXingWidget.a(ZXingWidgetController.o)
"_iconv", referenced from:
zxing::qrcode::DecodedBitStreamParser::append(std::basic_string<char, std::char_traits<char>, std::allocator<char> >&, unsigned char const*, unsigned long, char const*)in libZXingWidget.a(DecodedBitStreamParser-64E27B33E79CBC52.o)
"_OBJC_CLASS_$_AVCaptureSession", referenced from:
objc-class-ref-to-AVCaptureSession in libZXingWidget.a(ZXingWidgetController.o)
"_OBJC_CLASS_$_AVCaptureDevice", referenced from:
objc-class-ref-to-AVCaptureDevice in libZXingWidget.a(ZXingWidgetController.o)
"_kCVPixelBufferPixelFormatTypeKey", referenced from:
_kCVPixelBufferPixelFormatTypeKey$non_lazy_ptr in libZXingWidget.a(ZXingWidgetController.o)
(maybe you meant: _kCVPixelBufferPixelFormatTypeKey$non_lazy_ptr)
"_OBJC_CLASS_$_AVCaptureVideoDataOutput", referenced from:
objc-class-ref-to-AVCaptureVideoDataOutput in libZXingWidget.a(ZXingWidgetController.o)
"_CVPixelBufferGetWidth", referenced from:
-[ZXingWidgetController captureOutput:didOutputSampleBuffer:fromConnection:] in libZXingWidget.a(ZXingWidgetController.o)
"_AudioServicesDisposeSystemSoundID", referenced from:
-[ZXingWidgetController dealloc] in libZXingWidget.a(ZXingWidgetController.o)
"_OBJC_CLASS_$_AVCaptureDeviceInput", referenced from:
objc-class-ref-to-AVCaptureDeviceInput in libZXingWidget.a(ZXingWidgetController.o)
"_AVLayerVideoGravityResizeAspectFill", referenced from:
_AVLayerVideoGravityResizeAspectFill$non_lazy_ptr in libZXingWidget.a(ZXingWidgetController.o)
(maybe you meant: _AVLayerVideoGravityResizeAspectFill$non_lazy_ptr)
"_CMSampleBufferGetImageBuffer", referenced from:
-[ZXingWidgetController captureOutput:didOutputSampleBuffer:fromConnection:] in libZXingWidget.a(ZXingWidgetController.o)
"_iconv_open", referenced from:
zxing::qrcode::DecodedBitStreamParser::append(std::basic_string<char, std::char_traits<char>, std::allocator<char> >&, unsigned char const*, unsigned long, char const*)in libZXingWidget.a(DecodedBitStreamParser-64E27B33E79CBC52.o)
"_AVMediaTypeVideo", referenced from:
_AVMediaTypeVideo$non_lazy_ptr in libZXingWidget.a(ZXingWidgetController.o)
(maybe you meant: _AVMediaTypeVideo$non_lazy_ptr)
ld: symbol(s) not found
collect2: ld returned 1 exit status
I can include the needed frameworks in the parent project, but I thought that by including the frameworks in the library project the linking would be OK.
我可以在父项目中包含所需的框架,但我认为通过将框架包含在库项目中,链接就可以了。
My question is:Do I have to include all the frameworks that my dependent subprojects use in the parent project to ensure proper linking, or am I doing something wrong?
我的问题是:我是否必须包含我的依赖子项目在父项目中使用的所有框架以确保正确链接,还是我做错了什么?
Thanks for your help.
谢谢你的帮助。
采纳答案by Spencer Hakim
If the subproject compiles into a static lib, yes.
如果子项目编译成静态库,是的。
回答by wormlxd
make sure include "CoreMedia.framework","AudioToolbox.framework","CoreGraphics.framework","CoreVideo.framework","AVFoundation.framework","libiconv.dylib" frameworks in project in Build Phases
确保在构建阶段的项目中包含“CoreMedia.framework”、“AudioToolbox.framework”、“CoreGraphics.framework”、“CoreVideo.framework”、“AVFoundation.framework”、“libiconv.dylib”框架