Book Image

Getting started with LLVM core libraries

Book Image

Getting started with LLVM core libraries

Overview of this book

Table of Contents (17 chapters)
Getting Started with LLVM Core Libraries
Credits
About the Authors
About the Reviewers
www.PacktPub.com
Preface
Index

Obtaining prebuilt packages


To ease the task of installing the software on your system, LLVM contributors prepare prebuilt packages with the compiled binaries for a specific platform, as opposed to the requirement that you compile the package yourself. Compiling any piece of software can be tricky in some circumstances; it might require some time and should only be necessary if you are using a different platform or actively working on project development. Therefore, if you want a quick way to start with LLVM, explore the available prebuilt packages. In this book, however, we will encourage you to directly hack in to the LLVM source tree. You should be prepared to be able to compile LLVM from source trees yourself.

There are two general ways to obtain prebuilt packages for LLVM; you can obtain packages via distributed binaries in the official website or by third-party GNU/Linux distributions and Windows installers.

Obtaining the official prebuilt binaries

For version 3.4, the following prebuilt packages can be downloaded from the official LLVM website:

Architecture

Version

x86_64

Ubuntu (12.04, 13.10), Fedora 19, Fedora 20, FreeBSD 9.2, Mac OS X 10.9, Windows, and openSUSE 13.1

i386

openSUSE 13.1, FreeBSD 9.2, Fedora 19, Fedora 20, and openSUSE 13.1

ARMv7/ARMv7a

Linux-generic

To view all the options for a different version, access http://www.llvm.org/releases/download.html and check the Pre-built Binaries section relative to the version you want to download. For instance, to download and perform a system-wide installation of LLVM on Ubuntu 13.10, we obtain the file's URL at the site and use the following commands:

$ sudo mkdir -p /usr/local; cd /usr/local
$ sudo wget http://llvm.org/releases/3.4/clang+llvm-3.4-x86_64-linux-gnu-ubuntu-13.10.tar.xz
$ sudo tar xvf clang+llvm-3.4-x86_64-linux-gnu-ubuntu-13.10.tar.xz
$ sudo mv clang+llvm-3.4-x86_64-linux-gnu-ubuntu-13.10 llvm-3.4
$ export PATH="$PATH:/usr/local/llvm-3.4/bin"

LLVM and Clang are now ready to be used. Remember that you need to permanently update your system's PATH environment variable, since the update we did in the last line is only valid for the current shell session. You can test the installation by executing Clang with a simple command, which prints the Clang version you just installed:

$ clang –v

If you have a problem when running Clang, try to run the binary directly from where it was installed to make sure that you are not running into a misconfigured PATH variable issue. If it still doesn't work, you might have downloaded a prebuilt binary for an incompatible system. Remember that, when compiled, the binaries link against dynamic libraries with specific versions. A link error while running the application is a clear symptom of the use of a binary compiled to a system that is incompatible with yours.

Note

In Linux, for example, a link error can be reported by printing the name of the binary and the name of the dynamic library that failed to load, followed by an error message. Pay attention when the name of a dynamic library is printed on the screen. It is a clear sign that the system dynamic linker and loader failed to load this library because this program was not built for a compatible system.

To install prebuilt packages in other systems, the same steps can be followed, except for Windows. The prebuilt package for Windows comes with an easy-to-use installer that unpacks the LLVM tree structure in a subfolder of your Program Files folder. The installer also comes with the option to automatically update your PATH environment variable to be able to use Clang executables from within any command prompt window.

Using package managers

Package manager applications are available for a variety of systems and are also an easy way to obtain and install LLVM/Clang binaries. For most users, this is usually the recommended way to install LLVM and Clang, since it automatically handles dependency issues and ensures that your system is compatible with the installed binaries.

For example, in Ubuntu (10.04 and later), you should use the following command:

$ sudo apt-get install llvm clang

In Fedora 18, the command line used is similar but the package manager is different:

$ sudo yum install llvm clang

Staying updated with snapshot packages

Packages can also be built from nightly source code snapshots, containing the latest commits from the LLVM subversion repository. The snapshots are useful to LLVM developers and users who wish to test the early versions or to third-party users who are interested in keeping their local projects up-to-date with mainline development.

Linux

Debian and Ubuntu Linux (i386 and amd64) repositories are available for you to download the daily compiled snapshots from the LLVM subversion repositories. You can check for more details at http://llvm.org/apt.

For example, to install the daily releases of LLVM and Clang on Ubuntu 13.10, use the following sequence of commands:

$ sudo echo "deb http://llvm.org/apt/raring/ llvm-toolchain-raring main" >> /etc/apt/sources.list
$ wget -O - http://llvm.org/apt/llvm-snapshot.gpg.key | sudo apt-key add –
$ sudo apt-get update
$ sudo apt-get install clang-3.5 llvm-3.5
Windows

Windows installers of specific LLVM/Clang snapshots are available for download at http://llvm.org/builds/ in the Windows snapshot builds section. The final LLVM/Clang tools are installed by default in C:\Program Files\LLVM\bin (this location may change depending on the release). Note that there is a separate Clang driver that mimics Visual C++ cl.exe named clang-cl.exe. If you intend to use the classic GCC compatible driver, use clang.exe.

Note

Note that snapshots are not stable releases and might be highly experimental.