Install Clang / LLVM / Ubuntu

I need to use LLVM and Clang for the compiler class I'm registered to. This is not a question of the contents of this class, but simply how to install the necessary software.

I run gcc version 4.6.3 and download, create, test and update what I consider LLVM package version 3.4 (latest svn version). I am making a simple hello world application as indicated on the LLVM start page, but on the line

lli helloworld.bc 

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

I am a complete newbie with this material, so I donโ€™t know if I gave you everything you need to fix my mistake, write to me if you need to know something. Also, please try to give me as detailed instructions as possible ... I was thrown into the world of Ubuntu and Clang without any instructions, and I cannot read another โ€œsolutionโ€ that says โ€œread the manual pagesโ€.

Thank you so much for your help. I just want it set up so that I can at least try my homework.

EDIT :: Here are the EXTRACT instructions that I ran in the terminal, 99% of which were 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 this last line, lli hello.bc, where I get the error above.

In the first group of instructions, WHILE was executed. Something is definitely installed / built / something done. But I have no idea what is going on here.

So here are my big questions:

1) What is installed on my machine? I have to install both Clang and LLVM, right?

2) All my professor said: "We will use clang, and you need to get LLVM version 3.3 or later. Am I even on the right track? If not what should I do to get LLVM 3.3? The detailed guide I found on LLVM's website leads me to the problem described above.

+7
gcc linux ubuntu clang
source share
1 answer

When entering:

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

You used the system clang executable , which is located in /usr/bin/clang , and is not the clang that you just created. They have a different version. lli , however, is the lli you just created - Ubuntu does not come with it. This means that you created a .bc file with an old version of LLVM and then tried to run it with a newer version of LLVM, which is why the problem.

To test this, you can check which clang you are using by typing which clang in the console.

The easiest way to fix this is to type ./clang (or any other path that is not just a file name) instead of clang , which causes the shell to select a file in the current directory.

+8
source share

All Articles