When building a Swift command-line tool with associated Swift library why is the Framework being embedded?

吃可爱长大的小学妹 提交于 2019-12-11 04:54:25

问题


I've built a simple Swift project that produces a macOS command-line tool and has an associated custom Swift library (.dylib) but when compiling and running it there's a number of warnings that show up of the form:

objc[9532]: Class _SwiftNativeNSEnumeratorBase is implemented in both /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/macosx/libswiftCore.dylib (0x100cca3f0) and /Users/.../Build/Products/Debug/MyTool (0x1003e84c0). One of the two will be used. Which one is undefined.

Scanning the resulting MyTool binary shows that it contains that function, so I'm presuming it's been baked in somehow via static linking. The .dylib is expecting that to be present as a shared library, so it seems that's where the duplication comes about.

I've tried many settings in the project and target level, but none seem to control embedding things like the core Framework as a static library other than the explicit embed option.

For both targets Always Embed Swift Libraries is set to "No". Clean and build still produces the duplication warnings.


回答1:


It looks like there's a few things that have to be changed to resolve this:

  • Set the Runtime Search Paths to include /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/macosx or the appropriate library set. These seem to include a newer version of the Swift libraries than those present in the default location.
  • Set Link with Standard Libraries to "No".
  • Manually specify which libraries to link to on the "General" tab of the command-line target by dragging those in from the .../usr/lib/swift/macos location. A Swift project needs libswiftCore.dylib.

Due to C bindings I also had to include libc, but the default one (libc.tbc) sufficed.



来源:https://stackoverflow.com/questions/44168539/when-building-a-swift-command-line-tool-with-associated-swift-library-why-is-the

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!