[CMake] Swift executables with MACOSX_BUNDLE fail to find libswiftCore.dylib

Harry Mallon Harry.Mallon at codex.online
Fri Mar 2 14:12:42 EST 2018


Hello all,

When making a pure Swift bundle Xcode automatically copies `libswiftCore.dylib` as follows.

```
./Tests/SwiftOnly/Debug/SwiftOnly.app
└── Contents
    ├── Frameworks
    │   └── libswiftCore.dylib
    ├── Info.plist
    ├── MacOS
    │   └── SwiftOnly
    ├── PkgInfo
    └── Resources
        └── libswiftRemoteMirror.dylib
```
When I try to run the output I get a dynamic linking error. I can reproduce this by adding MACOSX_BUNDLE to `./Tests/SwiftOnly/CMakeLists.txt` (in the CMake source tree) in `add_executable` and trying to run the result.

```
% ./Tests/SwiftOnly/Debug/SwiftOnly.app/Contents/MacOS/SwiftOnly
dyld: Library not loaded: @rpath/libswiftCore.dylib
  Referenced from: .../Tests/SwiftOnly/Debug/SwiftOnly.app/Contents/MacOS/SwiftOnly
  Reason: image not found
zsh: abort      ./Tests/SwiftOnly/Debug/SwiftOnly.app/Contents/MacOS/SwiftOnly
```

It seems that the rpath should be set to `@loader_path/../Frameworks`. I am not a Swift maestro so not exactly sure on the details of how this works. After running `install_name_tool -add_rpath "@loader_path/../Frameworks" ./Tests/SwiftOnly/Debug/SwiftOnly.app/Contents/MacOS/SwiftOnly` it runs fine.

Does anyone have any idea what to do? Is it a missing CMake Swift feature? We are currently working around it by manually adding the rpath with a cmake step.

Harry

Harry Mallon

Senior Software Engineer

[http://codex.online/?action=asset&id=E3D62C3D-A12C-447D-87A5-F36E7C2AA9A4]<https://codex.online/>

T +44 203 7000 989<callto:+44%20203%207000%20989>

60 Poland Street | London | England | W1F 7NT

[http://codex.online/?action=asset&id=6F42BDF2-3C6D-4054-A5D2-277E0E535942]
Three Billboards        Blade Runner 2049        I, Tonya


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://cmake.org/pipermail/cmake/attachments/20180302/fee2b997/attachment.html>


More information about the CMake mailing list