2
votes

I used swift package init --type executable.

I have already tried setting xcode command line tools on path.

Following error occurs:

dyld: Library not loaded: @rpath/llbuild.framework/Versions/A/llbuild Referenced from: /Library/Developer/CommandLineTools/usr/bin/swift-package Reason: image not found

4

4 Answers

3
votes

I had to go into the preference for xcode and under Locations, set Command Line Tools to the correct version. It was blank when I first opened it.

0
votes

I have faced the similar issue. Basically the framework or library is not properly linked in the project.

If you are doing drag and drop of framework in xcode project then you will have to link it in embed frameworks as well. (Basically you will have to drag and drop the framework in embed frameworks section)

See the below image.

enter image description here

0
votes

There was this bad config in bash_profile /Library/Developer/CommandLineTools/usr/bin for path. Just removed it. Fixed the problem. which swift should result in /usr/bin/swift.

0
votes

I had the same problem. I wanted to do some simple command line coding but didn't want to install the full Xcode bloat. I installed only the Command Line Tools on Mojave 10.14.6.

I could call swiftc to compile a file from the command line which actually did everything I needed it to. (I can't remember where I found a reference to being able to do this but basically you just call 'swiftc filename.swift' and you're good.)

But it irritated me that coding the "proper" way (i.e. the way most of the tutorials on the Internet want you to) failed. The "swift package init..." stuff kept barfing with the error posted in the question above here. So I got obsessed with fixing it.

So the error says that swift-package can't find a tool called llbuild.

I found that the llbuild executable did actually exist on my machine at:

/Library/Developer/CommandLineTools/usr/lib/swift/pm/llbuild/llbuild.framework/

The error, then, is because swift-package isn't looking for the tool in that directory.

(As a side note, earlier in my quest to fix this error, I tried adding some paths to my .bash_profile. None of those attempts worked. I can't recall now if I ever tried adding that full path and I'm too lazy to try now.)

I did some more digging. Someone somewhere on the Internet pointed out that the @rpath (referenced in the error message) variable set in apps can be discovered with otools. I used otools on swift-package and found its @rpath seemed to be pointing to /usr/lib. I noticed there was a .../usr/lib/... structure in the location of llbuild mentioned above. I imagined that swift-package was looking in /usr/lib instead of the directory where the file actually was. So I linked the directory where llbuild really is into the /usr/lib directory and voila! It worked.

Most people who need to do this will likely know how to do a symlink of a directory, but just to be thorough, this is what solved the problem for me all as root or use sudo if you want:

cd /usr/lib
ln -s /Library/Developer/CommandLineTools/usr/lib/swift/pm/llbuild/llbuild.framework/ .

Note that trailing period there. That's necessary.

As a side note, I had System Integrity Protection turned on, which forbids making symlinks in /usr/lib, so I had to reboot and turn SIP off from the recovery login(reboot and hold down Command-R) before I could do this.

Also, note that none of this necessarily cured the underlying problem I had of being able to actually build swift packages from the command line--I could now use "swift package init" but I couldn't use "swift run" or do anything else useful. I posted this only to give others some clues when they go digging since I looked a lot of places and didn't have much luck.