LLVMSwift
LLVMSwift copied to clipboard
LLVMSwift as package dependency in Xcode
I have a Xcode 12.2 project where I would like to use LLVMSwift. I installed LLVM 9 with brew and followed Installation instructions. I then added LLVMSwift to my project with File > Swift Packages > Add Package Dependency…. The dependency references the latest commit on master.
When I compile my target, I get the following error: LLVMSwift/Sources/llvmshims/src/shim.cpp:1:10: fatal error: 'llvm-c/Core.h' file not found
.
From what I see in the output, flags defined in pkgconfig/cllvm.pc are missing. It's my first time using Swift Package Manager and I don't know how it interacts with pkg-config. Here is how cllvm.pc was generated:
$ swift [snip]/SourcePackages/checkouts/LLVMSwift/utils/make-pkgconfig.swift
Running /usr/bin/which llvm-config-9...
Running /usr/bin/which llvm-config...
Found llvm-config at /usr/local/opt/llvm@9/bin/llvm-config...
Running /usr/local/opt/llvm@9/bin/llvm-config --version...
LLVM version is 9.0.1
Running /usr/local/opt/llvm@9/bin/llvm-config --ldflags --libs all --system-libs...
Running /usr/local/opt/llvm@9/bin/llvm-config --cflags...
Writing pkg-config file to /usr/local/lib/pkgconfig/cllvm.pc...
Successfully wrote pkg-config file!
Hi @qmathe,
Try adding the dependency using "Up to Next Minor" with version 0.7. The latest commit on master
is part of what will eventually become 0.8 and requires LLVM 11 rather than 9.
I'm getting a similar error with LLVMSwift 0.8 when building with Xcode:
'llvm-c/Analysis.h' file not found
I have LLVM 11 installed with homebrew, and pkg-config script did succeed.
Make sure the llvm files installed by brew are in your PATH. Then rerun the pkg-config. Also see #235.
I do have export PATH="/opt/homebrew/opt/llvm@11/bin:$PATH"
in my .zshrc
, but that doesn't seem to have any effect on Xcode. Is there anything else that needs to be done to make Xcode aware of this LLVM installation?
Same problem for me. Any suggestions @matthewseaman?

Somehow rerunning swift utils/make-pkgconfig.swift
did help in my case after all.
Still same problem. I must be doing something different.


Do i need to use LLVM 11 instead?
Also check that you don't have two version of LLVM installed at the same time, I guess some of my issues could've been cause by having llvm@12
and llvm@13
installed by Homebrew at the same time. Also, you have to run make-pkgconfig.swift
every time after Homebrew installs or remove any of these packages, I think. I'm still not 100% sure what exactly worked in my case, but at one point I reran the script and Xcode builds started working again.
master
branch and 0.8.0 release need LLVM 11, while https://github.com/llvm-swift/LLVMSwift/pull/238 somewhat works with LLVM 13, but with disabled JIT.
Ok thanks, Max. I didn't have LLVM installed before using this package. It's a new machine and didn't even had Homebrew on it 😄
As far as I understand make-pkgconfig.swift
relies on Homebrew installations, but I could be wrong.
Ok, I need JIT. So I better use LLVM 11 then, remove 13 to make sure.
As far as I understand
make-pkgconfig.swift
relies on Homebrew installations, but I could be wrong.
Yes, I see it uses brew. Script runs fine though. But it must be because I installed LLVM 13 instead. Still weird it complains about missing headers and doesn't even pass compilation.
Good way to diagnose could be by using swift build
. If swift build
works, but building from Xcode doesn't, then it's the same issue I had 🙂
Running /opt/homebrew/bin/brew --prefix...
Running /usr/bin/which llvm-config-11...
Running /usr/bin/which llvm-config...
Found llvm-config at /opt/homebrew/opt/llvm@11/bin/llvm-config...
Running /opt/homebrew/opt/llvm@11/bin/llvm-config --version...
LLVM version is 11.1.0
Running /opt/homebrew/opt/llvm@11/bin/llvm-config --ldflags --libs all --system-libs...
Running /opt/homebrew/opt/llvm@11/bin/llvm-config --cflags...
Writing pkg-config file to /opt/homebrew/lib/pkgconfig/cllvm.pc...
Successfully wrote pkg-config file!
Make sure to re-run this script when you update LLVM.
henk@Henks-MacBook-Pro LLVMSwift % swift build
warning: failed to retrieve search paths with pkg-config; maybe pkg-config is not installed
warning: you may be able to install cllvm using your system-packager:
brew install llvm
/Users/henk/Library/Developer/Xcode/DerivedData/8-Bit_OS-eprcdyqouebnfjaxybvmskdpufrh/SourcePackages/checkouts/LLVMSwift/Sources/llvmshims/src/shim.cpp:1:10: fatal error: 'llvm-c/Core.h' file not found
#include "llvm-c/Core.h"
^~~~~~~~~~~~~~~
1 error generated.
[0/1] Compiling shim.cpp```
It does give more info. But still strange.
Oh wait. It said so to install pkg-config. That was it! Thanks for the help, Max!