在macOS上设置框架命令行应用程序 - 原因:找不到图像
我已经连续数周摔跤了。为什么下面的macOS安装程序给出了Alamofire链接程序错误?在macOS上设置框架命令行应用程序 - 原因:找不到图像
步骤重新创建链接错误:
- 创建新的MacOS命令行应用
- 运行荚初始化从终端更新
-
创建以下podfile:
平台:OSX,'10 0.10 ' target'testMacOS'do use_frameworks! 荚 'Alamofire', '〜> 4.0' 端
pod install
运行。打开并建立工作区
错误:dyld的:库未加载:@是rpath/Alamofire.framework /版本/ A/Alamofire 原因:未找到图像
AT这一点上,这个错误是有意义的。你需要去Target/General/Linked Frameworks和Libraries。然后添加Alamofire。现在Alamofire在工作区的Framework目录中。
构建并运行。同样的错误。为什么?
问题:使用xCode 8.1的,我没有意识到macOS Command Line应用程序不支持框架(动态库),就像iOS或桌面macOS应用程序使用捆绑软件一样。
解决方案:我通过关闭github源代码并在工作区内编译它来解决这个问题。这工作。导入静态库也起作用。
命令行工具确实“支持”框架,但不像应用程序捆绑包那样。你需要把引用的框架在@rpath
这实际上是~/Library/Frameworks/
或/Library/Frameworks/
您需要@rpath手动设置,荚“$(ProductDirectory)/ $(FrameworkName)/ $(FrameworkName).framework安装框架”。
例如,您的Alamofire框架位于“$(ProductDirectory)/Alamofire/Alamofire.framework”。因此,您需要将“@ executable_path/Alamofire /”添加到您自己的目标的Building Settings - Runpath Search Paths。此外,“Pods Project - Alamofire(Target)”还需要指定swift运行时动态库的位置。在我的环境中,我需要将“/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/macosx”添加到“Building Settings - Runpath Search Paths”中。
但为了方便起见,您可以看看我的pod post_install代码。
post_install do |installer|
files = Dir.glob("*.xcodeproj")
proj_file = files[0]
app_project = Xcodeproj::Project.open(proj_file)
app_project.native_targets.each do |target|
target.build_configurations.each do |config|
config.build_settings['LD_RUNPATH_SEARCH_PATHS'] = '$(inherited) @executable_path/../Frameworks @loader_path/Frameworks'
prefix = ' @executable_path/'
# For each pod, add the framework path to LD_RUNPATH_SEARCH_PATHS
installer.pods_project.targets.each do |pod_target|
config.build_settings['LD_RUNPATH_SEARCH_PATHS'] = config.build_settings['LD_RUNPATH_SEARCH_PATHS'] + prefix + pod_target.name + '/'
pod_target.build_configurations.each do |pod_config|
#if you want embed swift stdlib into every framework, uncommend 1,2 and commend 3,4
#1
#pod_config.build_settings['ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES'] = 'YES'
#2
#pod_config.build_settings['LD_RUNPATH_SEARCH_PATHS'] = '$(inherited) @executable_path/../Frameworks @loader_path/Frameworks'
#3
pod_config.build_settings['ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES'] = 'NO'
#4
pod_config.build_settings['LD_RUNPATH_SEARCH_PATHS'] = '$(inherited) /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/macosx/'
end
end
end
end
app_project.save
end