I have been building LLVM and clang 3.8 using svn for some time now. I started using git (this is not the cause of the problem) today and an error interrupted the build process that I have seen before. When make is trying to build the i386 sanitizer library it fails. I was able to disable building the sanitizers in ccmake by setting COMPILER_RT_BUILD_SANITIZERS to OFF. I would prefer to disable building the i386 target altogether. Does anyone know how to do this?
compiler-rt needs to be built out of tree. This is done so that it can be compiled with the newly built clang.
This process will only build the supported architecture, x86_64 in my case.
The following example uses the default install prefix (/usr/local)
to specify the location of llvm-config.
Once LLVM is built, change the directory to where you want compiler-rt
then:
svn co http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mkdir build
cd build
cmake ../compiler-rt -DLLVM_CONFIG_PATH=/usr/local/bin/llvm-config
make
make install
Related
I want to test Clang with CLion in ubuntu. By default Clion detects my gcc installation, but I want to use clang instead of gcc. Moreover, I don't want to install clang via apt-get. I have downloaded llvm, clang (3.6.2) binary from llvm website. I want to use that portable clang binaries.
Here is my system setup:
Ubuntu - 14.04
gcc - 4.8.4
llvm clang - 3.6.2 (portable)
CLion - 1.0.4
So how to set up CLion with llvm-clang here?
I got the answer from CLion blog and it works and here it goes.
To provide CMake compiler paths, go to Settings | Build, Execution, Deployment | CMake and pass as CMake options:
-D CMAKE_C_COMPILER=
-D CMAKE_CXX_COMPILER=
In case CMake fails to find some path to clang libs, etc. you can also set there environment variables:
CC=/usr/bin/clang
CXX=/usr/bin/clang++
The FAQ states the following:
At present CLion supports GCC and Clang compilers and is guided by these two to get the libraries and headers paths. In the next releases we are planning to extend the list of compilers available in CLion.
To change the compiler, go to the Cache tab in CMake tool window and set the compiler’s path to the CMAKE_CXX_COMPILER variable. Then press Enter and click the Apply Changes and Reload button
When I use the original versions (even 3.4.1) of LLVM/Clang to build FreeBSD kernel, it always has problems.
Since I need to modify something in LLVM source and then build the kernel, where can I get the FreeBSD-friendly Clang/LLVM source code (3.5 is better), or rebuild LLVM/Clang directly on FreeBSD? (it seems /usr/src/contrib/llvm/ has some source code but no Makefile)
New versions of Clang and LLVM are in ports/packages (eg. "pkg install clang35"). If you want to easily rebuild it with your changes, do "portsnap fetch update" to update your ports, "cd /usr/ports/lang/clang35", "make configure", then apply your changes to sources in /usr/ports/lang/clang35/work/ directory, and then do "make all install".
To rebuild LLVM version in the FreeBSD source tree, use the Makefiles in /usr/src/usr.bin/clang.
You can get the latest 3.5 source code via:
svn co http://llvm.org/svn/llvm-project/llvm/branches/release_35 llvm
cd llvm/tools
svn co http://llvm.org/svn/llvm-project/cfe/branches/release_35 clang
Then run
./configure --enable-optimized --disable-assertions
make
make install
in the top dir.
Edit/Update/Note: Just let clang use libstdc++. Has been working really well for me so far.
===============================
In the past I have been able to succeed by doing something with cmake, but just now I discovered a buildit script inside the lib directory of the http://llvm.org/svn/llvm-project/libcxx/trunk project tree.
This buildit script appears to not make use of libsupc++ which is what the cmake approach that I took earlier used. For instance, this guide shows one cmake incantation to produce a makefile for libc++, which will be able to take care of compiling and installation.
My question is what is the difference between these different ways to produce the LLVM-libc++ and which one should be used? Will they behave differently?
The buildit script does not appear to provide any help for installation. Are there directions anywhere for how to properly install the library? With my previous libc++ built with cmake, I had to always add -lc++ to the linker flags (and the path with -L), which is not necessary in my OS X makefiles.
The libc++ website has a nice overview of the possible ways to build libc++.
I suggest using CMake + libc++abi.
Also see the Arch Linux User Repository build script, which uses the buildit script. I installed libc++ from that and used it with the Arch Linux Clang package succesfully by using
clang++ -std=c++11 -stdlib=libc++ -lc++abi
I want to compile httpd into LLVM bytecode using clang. First I tried compiling it using gcc, for which I did the following:
./configure --prefix=/home/varun/apache/httpd/gcc --with-included-apr
make
sudo make install
And it successfully installs!
Now, I try compiling it with clang, for which I do the following:
CC="clang" CFLAGS="-O4" ./configure --prefix=/home/varun/apache/httpd/clang --with-included-apr
make # didn't come to this step
sudo make install # didn't come to this step
And, the configure itself fails. I chose -O4 as I read that LLVM outputs bytecode if you use -O4 or -emit-llvm as CFLAGS(neither of them work).
This is the error I get:
checking whether the C compiler works... no
configure: error: in `/home/varun/apache/httpd/httpd-2.4.3/srclib/apr':
configure: error: C compiler cannot create executables
Is this related to the the linker not being able to link the LLVM bytecode files?
[I knew it was something related to the linking step, but was not able to get things working. Finally compilation successful, so I'm writing my own answer]
Approach 1 (Failed)
Installed clang on my system using the Synaptic Package Manager.
Installed binutils-gold, because that is required to give the LLVMgold.so as a plugin to the linker. But for this the clang which was installed, should have the gold plugin.
Trying to configure httpd with this command:
CC="clang" CFLAGS="-O4" ./configure --prefix=/home/varun/work/httpd/build --with-included-apr
Here, --with-included-apr is required by httpd. -O4 is required so that the compilation happens through bytecode.
This configuration step itself fails, because the clang which is installed doesn't have the proper plugin for enabling the linker to link bytecode object files.
Approach 2 (Success)
Installed binutils-gold. Also obtained the source of binutils.
Compiling LLVM and using the binutils source code to compile, so that LLVM has the gold plugin.
Compile LLVM,
../configure --with-binutils-include=/usr/src/binutils/binutils-2.22/include --enable-gold --prefix=/usr/local
make
sudo make install
ln -s /usr/local/lib/LLVMgold.so /usr/lib/bdf-plugins/LLVMgold.so
Now, compile httpd
CC="clang" CFLAGS="-O4" ./configure --prefix=/home/varun/work/httpd/build --with-included-apr
make
sudo make install
LLVM bytecode is an intermediate representation used within LLVM. It cannot be executed by any machine. That's why the configure script is complaining that
C compiler cannot create executables.
Do not output LLVM bytecode. Try to use other optimization level instead. (and don't use -emit-llvm in CFLAGS as well).
I answered a very similar question here:
Generate LLVM IR for httpd
It is actually easy to build IR for most well written projects.
Shameless plug for our tool:
https://github.com/SRI-CSL/whole-program-llvm
Good luck.
The problem: Ubuntu 10.10 doesn't supply LLVM CMake modules (/usr/share/llvm) or (/usr/local/share/llvm) when installing LLVM 2.8 from Ubuntu repositories.
So I'm now compiling LLVM 2.8 using CMake by myself and then installing it like this:
cmake ..
make
make install
This will install CMake modules I need to link LLVM into my library. The problem is that when I compile LLVM using CMake, only static libraries are compiled. I saw in LLVM documentation, that you can compile shared libraries using this parameter into CMake:
cmake -DBUILD_SHARED_LIBS=true ..
But now, the CMake returns this error:
-- Target triple: i686-pc-linux-gnu
-- Native target architecture is X86
-- Threads enabled.
-- Building with -fPIC
-- Targeting Alpha
-- Targeting ARM
-- Targeting Blackfin
-- Targeting CBackend
-- Targeting CellSPU
-- Targeting CppBackend
-- Targeting Mips
-- Targeting MBlaze
-- Targeting MSP430
-- Targeting PIC16
-- Targeting PowerPC
-- Targeting Sparc
-- Targeting SystemZ
-- Targeting X86
-- Targeting XCore
-- Configuring done
CMake Error: The inter-target dependency graph contains the following strongly connected component (cycle):
"LLVMARMCodeGen" of type SHARED_LIBRARY
depends on "LLVMARMAsmPrinter"
"LLVMARMAsmPrinter" of type SHARED_LIBRARY
depends on "LLVMARMCodeGen"
At least one of these targets is not a STATIC_LIBRARY. Cyclic dependencies are allowed only among static libraries.
-- Build files have been written to: /llvm-2.8/build
And I cannot compile it as shared library, does anyone knows how to solve that problem ?
I need the shared libraries because they're dependencies of many other tools.
Summary
1) LLVM 2.8 from Ubuntu repository installs LLVM shared libraries but doesn't install CMake modules I need.
2) On the other side, if I compile LLVM by myself, it installs the CMake modules I need, but I can only do that when compiling LLVM as static library.
After a lot of investigation (google, source and llvmdev mail-list), I discovered that this problem is in fact an issue with the 2.8 release, the compilation of shared libraries using CMake in that release is broken. I'm porting my library now to the version 2.9rc1 which is working fine and was already scheduled to be released soon, thanks for all answers.
LLVM 2.8 documentation does not mention building with CMake.
Try ./configure --enable-shared
Try reading this page and then ask on the llvmdev list if that doesn't help.