Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Installing Clang/LLVM/Ubuntu

I am required to use LLVM and Clang for a compilers class I am enrolled in. This is not a question about the content of the class, just how to get the required software installed.

I am running gcc version 4.6.3 and have downloaded, built, tested, and updated what I believe to be LLVM suite version 3.4 (the latest svn edition). I do a simple "hello world" application, as referenced on the LLVM getting started page, but on the line

lli helloworld.bc

I get the error "lli:helloworld.bc: Invalid MODULE_CODE_GLOBALVAR record"

Here are the instructions I ran in the terminal, most of which was taken directly from the LLVM website:

cd myFolder
svn co http://llvm.org/svn/llvm-project/llvm/trunk llvm
cd myFolder
cd llvm/tools
svn co http://llvm.org/svn/llvm-project/cfe/trunk clang
cd myFolder
cd llvm/projects
svn co http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
cd myFolder
mkdir build
cd build
../llvm/configure --enable-optimized CC=/usr/bin/clang CXX=/usr/bin/clang++
make
make check-all
make update

THEN

clang hello.c -o hello
clang -03 -emit-llvm hello.c -c -o hello.bc
lli hello.bc

And that final line, lli hello.bc, is where I get the error above.

Here are my questions:

  1. What is installed on my machine? How do I resolve this error?

  2. My professor said we need clang and LLVM 3.3. How can I get LLVM 3.3?

like image 532
Mike T Avatar asked Aug 28 '13 04:08

Mike T


1 Answers

When you typed:

clang -03 -emit-llvm hello.c -c -o hello.bc

You used the system's clang executable, which is at /usr/bin/clang, and is not the clang you have just built. The two have a different version. lli, however, is the lli you've just built - Ubuntu doesn't come with it. That means you have generated a .bc file with an older LLVM version and then tried to run it with a newer LLVM version, hence the problem.

To verify this, you can check which clang you are using by typing which clang into the console.

The simplest way to remedy this is to type ./clang (or any other path which isn't just the file name) instead of clang, which forces the shell to choose the file in the current directory.

like image 147
Oak Avatar answered Oct 12 '22 18:10

Oak