How to include a third party binary in Xcode?

2019-09-18 00:11发布

问题:

I am learning code here - a video player on Mac OS X depends on MPlayerX: https://bitbucket.org/Tomasen/splayerx/src/ Have something confused with binary including in Xcode: https://bitbucket.org/Tomasen/splayerx/src/a97f03511dfc/binaries/x86_64 there is a binary called mplayer-mt(not .a file, it's exectuable) How is the binary used in Xcode? How to import it or how to config?

Here is my build fail info:

Ld /Users/tsung/Library/Developer/Xcode/DerivedData/loss-fqhksenkliuhradvuyhbrddeakha/Build/Products/Debug/loss.app/Contents/MacOS/loss normal x86_64 cd /Users/tsung/works/mac/loss 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/tsung/Library/Developer/Xcode/DerivedData/loss-fqhksenkliuhradvuyhbrddeakha/Build/Products/Debug -L/Users/tsung/works/mac/loss/binaries/x86_64/lib -F/Users/tsung/Library/Developer/Xcode/DerivedData/loss-fqhksenkliuhradvuyhbrddeakha/Build/Products/Debug -filelist /Users/tsung/Library/Developer/Xcode/DerivedData/loss-fqhksenkliuhradvuyhbrddeakha/Build/Intermediates/loss.build/Debug/loss.build/Objects-normal/x86_64/loss.LinkFileList -mmacosx-version-min=10.8 -fobjc-link-runtime -framework Cocoa -o /Users/tsung/Library/Developer/Xcode/DerivedData/loss-fqhksenkliuhradvuyhbrddeakha/Build/Products/Debug/loss.app/Contents/MacOS/loss

Undefined symbols for architecture x86_64: "_MPLog", referenced from: -[PlayerController playMedia:] in PlayerController.o -[PlayerController playebackStarted] in PlayerController.o "_OBJC_CLASS_$_CoreController", referenced from: objc-class-ref in PlayerController.o "_OBJC_CLASS_$_PlayList", referenced from: objc-class-ref in PlayerController.o "_OBJC_CLASS_$_StoreHandler", referenced from: objc-class-ref in OSDView.o "_OBJC_CLASS_$_ssclThread", referenced from: objc-class-ref in PlayerController.o "_kI386Key", referenced from: -[PlayerController setMultiThreadMode:] in PlayerController.o "_kKVOPropertyKeyPathAudioDelay", referenced from: -[PlayerController setupKVO] in PlayerController.o -[PlayerController dealloc] in PlayerController.o "_kKVOPropertyKeyPathAudioInfo", referenced from: -[PlayerController setupKVO] in PlayerController.o -[PlayerController dealloc] in PlayerController.o "_kKVOPropertyKeyPathAudioInfoID", referenced from: -[PlayerController setupKVO] in PlayerController.o -[PlayerController dealloc] in PlayerController.o "_kKVOPropertyKeyPathCachingPercent", referenced from: -[PlayerController setupKVO] in PlayerController.o -[PlayerController dealloc] in PlayerController.o "_kKVOPropertyKeyPathCurrentTime", referenced from: -[PlayerController setupKVO] in PlayerController.o -[PlayerController dealloc] in PlayerController.o "_kKVOPropertyKeyPathLength", referenced from: -[PlayerController setupKVO] in PlayerController.o -[PlayerController dealloc] in PlayerController.o "_kKVOPropertyKeyPathSeekable", referenced from: -[PlayerController setupKVO] in PlayerController.o -[PlayerController dealloc] in PlayerController.o "_kKVOPropertyKeyPathSpeed", referenced from: -[PlayerController setupKVO] in PlayerController.o -[PlayerController dealloc] in PlayerController.o "_kKVOPropertyKeyPathSubDelay", referenced from: -[PlayerController setupKVO] in PlayerController.o -[PlayerController dealloc] in PlayerController.o "_kKVOPropertyKeyPathSubInfo", referenced from: -[PlayerController setupKVO] in PlayerController.o -[PlayerController dealloc] in PlayerController.o "_kKVOPropertyKeyPathSubScale", referenced from: -[PlayerController setupKVO] in PlayerController.o -[PlayerController dealloc] in PlayerController.o "_kKVOPropertyKeyPathVideoInfo", referenced from: -[PlayerController setupKVO] in PlayerController.o -[PlayerController dealloc] in PlayerController.o "_kKVOPropertyKeyPathVideoInfoID", referenced from: -[PlayerController setupKVO] in PlayerController.o -[PlayerController dealloc] in PlayerController.o "_kMPCPlayStoppedByForceKey", referenced from: -[PlayerController playebackStopped:] in PlayerController.o "_kMPCPlayStoppedTimeKey", referenced from: -[PlayerController playebackStopped:] in PlayerController.o "_kMPCStringMPlayerX", referenced from: -[PlayerController init] in PlayerController.o "_kPMValDemuxFFMpeg", referenced from: -[PlayerController playMedia:] in PlayerController.o "_kUDKeyAC3PassThrough", referenced from: +[PlayerController initialize] in PlayerController.o -[PlayerController playMedia:] in PlayerController.o "_kUDKeyAPNFuzzy", referenced from: +[PlayerController initialize] in PlayerController.o "_kUDKeyAutoPlayNext", referenced from: +[PlayerController initialize] in PlayerController.o -[PlayerController playebackStopped:] in PlayerController.o "_kUDKeyAutoResume", referenced from: +[PlayerController initialize] in PlayerController.o -[PlayerController playMedia:] in PlayerController.o "_kUDKeyCacheSize", referenced from: +[PlayerController initialize] in PlayerController.o -[PlayerController playMedia:] in PlayerController.o "_kUDKeyCachingLocal", referenced from: +[PlayerController initialize] in PlayerController.o -[PlayerController playMedia:] in PlayerController.o "_kUDKeyDTSPassThrough", referenced from: +[PlayerController initialize] in PlayerController.o -[PlayerController playMedia:] in PlayerController.o "_kUDKeyEnableMultiThread", referenced from: +[PlayerController initialize] in PlayerController.o -[PlayerController init] in PlayerController.o "_kUDKeyFFMpegHandleStream", referenced from: -[PlayerController playMedia:] in PlayerController.o "_kUDKeyForceIndex", referenced from: +[PlayerController initialize] in PlayerController.o -[PlayerController playMedia:] in PlayerController.o "_kUDKeyLetterBoxHeight", referenced from: +[PlayerController initialize] in PlayerController.o -[PlayerController playMedia:] in PlayerController.o "_kUDKeyLetterBoxMode", referenced from: +[PlayerController initialize] in PlayerController.o -[PlayerController playMedia:] in PlayerController.o "_kUDKeyLetterBoxModeAlt", referenced from: +[PlayerController initialize] in PlayerController.o "_kUDKeyMixToStereoMode", referenced from: +[PlayerController initialize] in PlayerController.o -[PlayerController playMedia:] in PlayerController.o "_kUDKeyOSDAutoHideTime", referenced from: +[OSDView initialize] in OSDView.o -[OSDView initWithFrame:] in OSDView.o "_kUDKeyOSDFontSizeMax", referenced from: +[OSDView initialize] in OSDView.o -[OSDView setStringValue:type:updateTimer:] in OSDView.o "_kUDKeyOSDFontSizeMin", referenced from: +[OSDView initialize] in OSDView.o -[OSDView setStringValue:type:updateTimer:] in OSDView.o "_kUDKeyOSDFrontColor", referenced from: +[OSDView initialize] in OSDView.o -[OSDView initWithFrame:] in OSDView.o "_kUDKeyOverlapSub", referenced from: +[PlayerController initialize] in PlayerController.o -[PlayerController playMedia:] in PlayerController.o "_kUDKeyPlayWhenOpened", referenced from: +[PlayerController initialize] in PlayerController.o -[PlayerController playMedia:] in PlayerController.o -[PlayerController playebackStopped:] in PlayerController.o "_kUDKeyPrefer64bitMPlayer", referenced from: +[PlayerController initialize] in PlayerController.o -[PlayerController shouldRun64bitMPlayer] in PlayerController.o "_kUDKeyPreferIPV6", referenced from: +[PlayerController initialize] in PlayerController.o -[PlayerController playMedia:] in PlayerController.o "_kUDKeyRtspOverHttp", referenced from: +[PlayerController initialize] in PlayerController.o -[PlayerController playMedia:] in PlayerController.o "_kUDKeySmartSubMatching", referenced from: +[PlayerController initialize] in PlayerController.o -[PlayerController playMedia:] in PlayerController.o -[PlayerController playebackStarted] in PlayerController.o "_kUDKeySubFileNameRule", referenced from: +[PlayerController initialize] in PlayerController.o -[PlayerController playMedia:] in PlayerController.o -[PlayerController findFirstMediaFileFromSubFile:] in PlayerController.o "_kUDKeySubFontBorderColor", referenced from: +[PlayerController initialize] in PlayerController.o -[PlayerController playMedia:] in PlayerController.o "_kUDKeySubFontColor", referenced from: +[PlayerController initialize] in PlayerController.o -[PlayerController playMedia:] in PlayerController.o "_kUDKeySubFontPath", referenced from: +[PlayerController initialize] in PlayerController.o -[PlayerController init] in PlayerController.o "_kUDKeySubScale", referenced from: +[PlayerController initialize] in PlayerController.o -[PlayerController playMedia:] in PlayerController.o -[PlayerController changeSubScaleBy:] in PlayerController.o -[PlayerController setSubScale:] in PlayerController.o "_kUDKeySubScaleStepValue", referenced from: +[PlayerController initialize] in PlayerController.o "_kUDKeyTextSubtitleCharsetConfidenceThresh", referenced from: -[PlayerController subConverter:detectedFile:ofCharsetName:confidence:] in PlayerController.o "_kUDKeyTextSubtitleCharsetFallback", referenced from: -[PlayerController subConverter:detectedFile:ofCharsetName:confidence:] in PlayerController.o "_kUDKeyTextSubtitleCharsetManual", referenced from: -[PlayerController subConverter:detectedFile:ofCharsetName:confidence:] in PlayerController.o "_kUDKeyThreadNum", referenced from: +[PlayerController initialize] in PlayerController.o -[PlayerController setMultiThreadMode:] in PlayerController.o "_kUDKeyUseEmbeddedFonts", referenced from: +[PlayerController initialize] in PlayerController.o -[PlayerController playMedia:] in PlayerController.o "_kX86_64Key", referenced from: -[PlayerController setMultiThreadMode:] in PlayerController.o ld: symbol(s) not found for architecture x86_64 clang: error: linker command failed with exit code 1 (use -v to see invocation)

回答1:

Your linker has failed, and linkers do not have anything to do with files that are directly executable outside of XCode. At least as far as I know.

Instead have you tried to include the .dylib files from your library in your xcode build? Download them locally and then use the "Link Binary With Libraries" section of the "Build Phases" tab to add them to your current project, using the plus button.

If you haven't done this before, you have to click on your target in the left hand window to find either these items.



回答2:

Found that the author of SPlayerX start the binary with arguments but not embed. Check it out here if you are interested: PlayerCore.m