Xcode - dyld: Library not loaded

561 views Asked by At

I trying to use GCDWebServer installed with cocoapods in my Cocoa Application and it's works fine!

But when I try to do the same in Command Line Tool Application I get this error -

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) 

Code of my 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

There are 1 answers

0
artyom.razinov On BEST ANSWER

Patch your Podfile according to:

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

The version I use for my hello world CLI app:

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

It is more a workaround than a solution.