Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to enable shared library build while using CMake for LLVM?

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.

like image 926
Tarantula Avatar asked Mar 19 '11 13:03

Tarantula


People also ask

How do you build with CMake?

To build with just cmake change directory into where you want the binaries to be placed. For an in-place build you then run cmake and it will produce a CMakeCache. txt file that contains build options that you can adjust using any text editor.

How long does it take to build LLVM from source?

You can invoke CMake with -DCMAKE_BUILD_TYPE=Debug to produce a clang binary with assertions enabled. This takes only about 60 minutes to build, but you wouldn't want to use the resulting binary for anything heavy-duty because it's so slow.


2 Answers

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.

like image 116
Tarantula Avatar answered Oct 12 '22 23:10

Tarantula


LLVM 2.8 documentation does not mention building with CMake.

Try ./configure --enable-shared

like image 43
Adam Mitz Avatar answered Oct 13 '22 01:10

Adam Mitz