Xcode - dyld:未加载库

时间:2017-11-28 15:03:46

标签: xcode xcode8 command-line-tool gcdwebserver

我尝试在我的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 个答案:

答案 0 :(得分:2)

根据以下内容修补您的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

与其说是解决方案,不如说是替代方法。