macOS Command Line Tool with Swift Cocoa Framework: Library not loaded

后端 未结 3 845
长发绾君心
长发绾君心 2020-12-28 13:05

The following error is thrown when trying to run my target:

dyld: Library not loaded: @rpath/libswiftCore.dylib
  Referenced from: x/Xcode/DerivedData/x/Buil         


        
相关标签:
3条回答
  • 2020-12-28 13:45

    In your "Command Line Tool" Target.. set the following...

    LD_RUNPATH_SEARCH_PATHS = @executable_path
    

    (Or as Xcode calls them, "Runtime Search Paths") Setting this, the @rpath, in essence, says.. "hey, look in whatever folder the 'tool' is running in" for the dynamically loadable libs. (In this case it will be your build folder.

    Other useful @rpath combinations involve similarly relative paths to the executable (which may also be a library or framework binary, in some cases), via @loader_path. Say if the lib was bundled within a framework.. It may require the LD_RUNPATH_SEARCH_PATHS of @loader_path/Frameworks, etc.

    0 讨论(0)
  • 2020-12-28 13:46

    The above worked for me. the two user build flags and then setting the following in runtime search paths.

    LD_RUNPATH_SEARCH_PATHS = $(TOOLCHAIN_DIR)/usr/lib/swift/macosx @executable_path
    
    0 讨论(0)
  • 2020-12-28 13:59

    Swift Package Manager sets the following, which resolved this issue for me in another project:

    SWIFT_FORCE_DYNAMIC_LINK_STDLIB = YES
    SWIFT_FORCE_STATIC_LINK_STDLIB = NO
    

    Note that the search path was set to:

    LD_RUNPATH_SEARCH_PATHS = $(TOOLCHAIN_DIR)/usr/lib/swift/macosx @executable_path
    
    0 讨论(0)
提交回复
热议问题