jocal17
jocal17

Reputation: 51

Differences between Apple LLVM and LLVM

I have Apple's command line tools version 9.1 installed and am working through an LLVM tutorial. I need to use some libraries like llvm/ADT and llvm/IR but get an error when I run the code.

main.cpp:1:10: fatal error: 'llvm/ADT/APFloat.h' file not found
#include "llvm/ADT/APFloat.h"
         ^~~~~~~~~~~~~~~~~~~~
1 error generated.

I also don't seem to have tools such as the assembler. Are these things not usable with Apple's version? And can I install LLVM without conflicting with Apple's version?

Upvotes: 2

Views: 1696

Answers (2)

AlexDenisov
AlexDenisov

Reputation: 4117

Actually, there is no need to build the LLVM yourself. You can get prebuilt version for your platform here: http://releases.llvm.org

In your case it would be something like this:

cd /opt
wget http://releases.llvm.org/5.0.0/clang+llvm-5.0.0-x86_64-apple-darwin.tar.xz
tar xvf clang+llvm-5.0.0-x86_64-apple-darwin.tar.xz
mv clang+llvm-5.0.0-x86_64-apple-darwin llvm-5.0.0

After that you will have everything under /opt/llvm-5.0.0, e.g.:

/opt/llvm-5.0.0/bin/clang
/opt/llvm-5.0.0/bin/llvm-config
/opt/llvm-5.0.0/lib/libc++.a

etc.

P.S. I use /opt just as an example, feel free to pick any other directory that fits you best.

Upvotes: 2

Zhang HanSheng
Zhang HanSheng

Reputation: 342

Apple's fork misses most of the library,headers and command-line tools in the llvm trunk.
I suggest you compile a new llvm copy from trunk.

Conflicting depends on how you configure everything. You can:

  • Install your new copy to global location, where your $PATH configuration is responsible for choosing which version to use.
  • Install as a separate Xcode Toolchain.

Here is a build script I've been using: cmake -G "Ninja" -DCMAKE_BUILD_TYPE=Release -DLLVM_APPEND_VC_REV=on -DLLVM_ENABLE_EH=on -DLLVM_ENABLE_RTTI=on -DLLVM_CREATE_XCODE_TOOLCHAIN=on -DCMAKE_INSTALL_PREFIX=~/Library/Developer/ ../LLVM Running ninja install will install to global location, otherwise run ninja install-xcode-toolchain to install as a separate toolchain

In your case I suggest installing to global location to avoid the trouble of messing with CFLAGS/LDFLAGS/Header Search Path. Then remove the installation manually after you are done with the tutorial

EDIT: You might also want to check out the official build guide https://llvm.org/docs/CMake.html
For your use case, in-tree building is also a feasible option(Providing you are familiar with write cmake configs)

Upvotes: 3

Related Questions