I always wanted to try this LLVM. It is said that the error message is better than GCC, and C ++ 11 supports more. At the time of compilation today, I found that several C ++ 11 features were used, and gcc4.4 could not be compiled. So I thought, let's try LLVM.
Since we want to install a newer version of LLVM, the new software package is definitely not a good choice. If you want to use the pre-compiled. deb package, you find that ubuntu10.04 is not supported. It seems that deb packages can be used after 11.10. Let's compile the source code. This should always work.
Objective: To compile LLVM and Clang C/C ++,
Ubuntu 10.04, X86, and gcc4.4.
First, find out what to prepare.
Download the required source code first,
(A) LLVM source code,
In a folder named temp,
Svn co http://llvm.org/svn/llvm-project/llvm/trunk llvm
After the download is complete, you can see that there is a llvm folder under temp.
(B) Clang source code
Switch to the following folder first,
Cd llvm/tools
Svn co http://llvm.org/svn/llvm-project/cfe/trunk clang
(C) extra Clang tools, which is optional,
Similarly, you need to switch the folder first. Note that the current directory is temp when switching.
Cd llvm/tools/clang/tools
Svn co http://llvm.org/svn/llvm-project/clang-tools-extra/trunk extra
(D) The last source code, Compiler-RT
Cd llvm/projects
Svn co http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
Next we will start to compile,
Now create a build folder under temp to store the compiled items.
Enter the build folder to generate the configuration file.
Cd build
../Llvm/configure [option]
Check the dependent environment. If no problem exists, the makefile is generated.
In configure, you can add some options.
In the Local LLVM Configuration section (http://llvm.org/docs/GettingStarted.html#local-llvm-configuration), you can see the supported options,
Here I use -- enable-optimized (enable optimization, svn gets the default value is not open, will generate debug related content, feel unnecessary, and will occupy a large space, no)
Another option is -- enable-targets = target-option. It is very important to select the target platform. Generally, you can use host-only, you only need to adapt to the situation of the local machine,
All platforms are generated by default, which is unnecessary.
Another option is assert, -- enable-assertions. Do you need this? It is not clear that it is enabled by default. You can use -- disable-assertions to disable it. I guess so, it seems that I didn't see how to disable it. Other options are ignored.
Another configuration option is that it is only applicable to C/C ++, including Python, and does not need to be used in all languages. This can be done as described in the document, but I cannot find out how to do it.
Make starts after makefile is generated. Make can specify multiple threads to work simultaneously, such as make-j2. Other make clean and make dist-clean can also be used. (After compiling for a long time, I knew I would have used-j2, and I would have just two cores.-j4 would not have changed much)
The last step is make install. It is installed under/usr/local/by default.
In this way, clang should be installed, and the next thing to do is install libc ++. This is a standard library implemented for C ++ 11. Since LLVM is installed only for C ++ 11, it must also be installed.
Http://www.cnblogs.com/ralphjzhang/archive/2011/12/02/2272671.html
In. In this case, you must use libc ++ directly.
The installation method is as follows.
In the temp directory mentioned above, the source code is still downloaded using svn,
Svn co http://llvm.org/svn/llvm-project/libcxx/trunk libcxx
Then,
Cd libcxx/lib
./Buildit
The required dynamic library file, libc ++. so.1.0, is generated under lib. At this point, the blog post is still correct, and the Post is actually correct, but there are some problems when establishing links.
Sudo cp./libc ++. so.1.0/usr/lib
Cd/usr/lib
Sudo ln-sf/usr/lib/libc ++. so.1.0 libc ++. so
Sudo ln-sf/usr/lib/libc ++. so.1.0 libc ++. so.1
The difference is that the target link of the ln-sf source file uses an absolute path. In this way, there will be three files under/usr/lib.
Why should we have these three files? When compiling the link,-lc ++ or stdlib = libc ++ will be linked to libc ++. so, and when running, libc ++ is required. so.1. I don't know why, but if not, errors will occur during compilation and running. Use the example in the blog post to pass the test.
The following is how to use StackOverflow, http://stackoverflow.com/questions/10601545/clang-3-1-and-c11-support-status
# Uses clang's C ++ library in C ++ 98 mode
Clang ++-stdlib = libc ++ [input] # uses clang's C ++ library
# Uses clang's C ++ library and enables C ++ 11 mode
Clang ++-stdlib = libc ++-std = c ++ 11 [input]
Clang ++-stdlib = libc ++-std = c ++ 0x [input]
You can use it first.