Cocoapods: Command Line Tool + CocoaPods frameworks breaks

Created on 20 Jun 2015  路  14Comments  路  Source: CocoaPods/CocoaPods

I tried to use the new frameworks feature with an OS X Command Line tool, and it complained about missing images. I had to add the following to my Runpath search paths: @executable_path/../Pods, and everything works again. Not sure at which level this should be solved or what I could do to help :).

defect discussion

Most helpful comment

It's not a solution, just a stupid patch, but maybe it would help somehow somebody:

post_install do |installer|
  installer.pods_project.targets.each do |target|
    if target.name =~ /-macOS$/
      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
end

It raises warnings like Class _SwiftNativeNSStringBase is implemented in both /System/Library/PrivateFrameworks/Swift/libswiftCore.dylib (0x7fffa52a6dc0) and ... One of the two will be used. Which one is undefined., but at least works in my case.

All 14 comments

Looks like this can be a pretty complex problem when working with Swift too: https://colemancda.github.io/programming/2015/02/12/embedded-swift-frameworks-osx-command-line-tools/

I don't think it is entirely solvable by us, considering that there is no "standard" way to distribute frameworks alongside a command line tool.

Also, always worth to plug https://github.com/neonichu/cato when talking about Swift CLI tools :)

I suppose Xcode should be adding the frameworks location to the run path search paths?

This issue has been inactive for a long time and will be closed because we want to move forward with a clean slate after our 1.0 release.

I know this is a closed issue.... But I have been able to make some progress here by embedding the command app inside a GUI app ... (and then i can symlink to it from /usr/local/bin or something like that ) but when I do that it seems like the swift frameworks are getting linked twice...

Class _TtC10Foundation25NSFastEnumerationIterator is implemented in both ...MyApp.app/Contents/Frameworks/libswiftFoundation.dylib (0x106d54720) and ...MyApp.app/Contents/MacOS/./myapp-cli (0x10621ce40). One of the two will be used. Which one is undefined.

It's not a solution, just a stupid patch, but maybe it would help somehow somebody:

post_install do |installer|
  installer.pods_project.targets.each do |target|
    if target.name =~ /-macOS$/
      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
end

It raises warnings like Class _SwiftNativeNSStringBase is implemented in both /System/Library/PrivateFrameworks/Swift/libswiftCore.dylib (0x7fffa52a6dc0) and ... One of the two will be used. Which one is undefined., but at least works in my case.

@bonkey you might think it's stupid, but it saved me a lot of hair pulling! thankyou

I was just creating a standard C++ command line tool and it worked if I just turned all of my pods into static libraries like this:

post_install do |installer|
  installer.pods_project.targets.each do |target|
    target.build_configurations.each do |config|
        config.build_settings['MACH_O_TYPE'] = 'staticlib'
    end
  end
end

Cheers to @bonkey for the idea!

For anyone stumbling upon this through google, this plugin is really great and basically solves the problem with minimal changes by embedding all pods into the executable itself:

https://github.com/Ruenzuo/cocoapods-amimono

@jariz Just for future reference, the cocoapods-amimono project is dead, not working from cocoapods 1.5 :/

I made a 'fork' here. It's very unsupported and undocumented, I might do so at some point, but just for your reference:
https://github.com/jariz/Akku/tree/master/cocoapods-amimono

I was just creating a standard C++ command line tool and it worked if I just turned all of my pods into static libraries like this:

post_install do |installer|
  installer.pods_project.targets.each do |target|
    target.build_configurations.each do |config|
        config.build_settings['MACH_O_TYPE'] = 'staticlib'
    end
  end
end

Cheers to @bonkey for the idea!

THANK YOU,

I am new to XCode, and after spending several hours trying to figure this out your solution worked.
Doing this using Gradle for a Kotlin command line project is a lot simpler..

image

target 'CocoaPodsy' do
  # Comment the next line if you don't want to use dynamic frameworks
  # use_frameworks!

  # Pods for CocoaPodsy
  pod 'RxSwift', '6.0.0'
  pod 'RxCocoa', '6.0.0'
end

post_install do |installer|
  installer.pods_project.targets.each do |target|
    target.build_configurations.each do |config|
      config.build_settings['MACH_O_TYPE'] = 'staticlib'
    end
  end
end

and my libraries were static, and I was able to just include them in my project

image

It might be more robust to use use_frameworks! :linkage => :static instead of the post_install script.

It might be more robust to use use_frameworks! :linkage => :static instead of the post_install script.

I replaced it with your suggestion, and didn't work for me. Thanks anyways.

Was this page helpful?
0 / 5 - 0 ratings