Xcode - dyld:库未加载

Posted

技术标签:

【中文标题】Xcode - dyld:库未加载【英文标题】:Xcode - dyld: Library not loaded 【发布时间】:2017-11-28 15:03:46 【问题描述】:

我尝试在我的 Cocoa 应用程序中使用与 cocoapods 一起安装的 GCDWebServer,它工作正常!

但是当我尝试在命令行工具应用程序中执行相同操作时,我收到此错误 -

dyld: Library not loaded: @rpath/GCDWebServer.framework/Versions/A/GCDWebServer
  Referenced from: /Users/username/Library/Developer/Xcode/DerivedData/test-cjiasulvnyulqidyrsqipangmbfh/Build/Products/Debug/test
  Reason: image not found
(lldb) 

我的 main.m 的代码 -

#import "GCDWebServer.h"
#import "GCDWebServerDataResponse.h"

int main(int argc, const char* argv[]) 
  @autoreleasepool 

    // Create server
    GCDWebServer* webServer = [[GCDWebServer alloc] init];

    // Add a handler to respond to GET requests on any URL
    [webServer addDefaultHandlerForMethod:@"GET"
                             requestClass:[GCDWebServerRequest class]
                             processBlock:^GCDWebServerResponse *(GCDWebServerRequest* request) 

      return [GCDWebServerDataResponse responseWithhtml:@"<html><body><p>Hello World</p></body></html>"];

    ];

    // Use convenience method that runs server on port 8080
    // until SIGINT (Ctrl-C in Terminal) or SIGTERM is received
    [webServer runWithPort:8080 bonjourName:nil];
    NSLog(@"Visit %@ in your web browser", webServer.serverURL);

  
  return 0;

【问题讨论】:

【参考方案1】:

根据以下内容修补您的 Podfile:

https://github.com/CocoaPods/CocoaPods/issues/3707

我用于 hello world CLI 应用的版本:

post_install do |installer|
  installer.pods_project.targets.each do |target|
    target.build_configurations.each do |config|
      config.build_settings['DYLIB_INSTALL_NAME_BASE'] = target.product_name
      config.build_settings['ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES'] = 'YES'
    end
  end
end

与其说是解决方案,不如说是一种变通方法。

【讨论】:

以上是关于Xcode - dyld:库未加载的主要内容,如果未能解决你的问题,请参考以下文章

dyld:库未加载Xcode11

Xcode 13 dyld:库未加载:/System/Library/Frameworks/LinkPresentation.framework/LinkPresentation

dyld:库未加载...原因:找不到合适的图像 Xcode Swift

Xcode 5.0.2 dyld:库未加载:@rpath/XCTest.framework/Versions/A/XCTest

dyld:库未加载:@rpath/libswiftCore.dylib

dyld:库未加载:@rpath/libswiftAVFoundation.dylib