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

10,900

Solution 1

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.

Solution 2

LLVM 2.8 documentation does not mention building with CMake.

Try ./configure --enable-shared

Share:
10,900
Tarantula
Author by

Tarantula

Updated on June 06, 2022

Comments

  • Tarantula
    Tarantula almost 2 years

    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.

  • Adam Mitz
    Adam Mitz about 13 years
    Care to explain downvote? If the LLVM developers don't endorse using CMake, how can we expect it to work?
  • rubenvb
    rubenvb about 13 years
    (I'm not the downvoter, but...) I'm sure they would be glad to help get the bugs out of their CMake build. llvmdev is a very helpful mailing list.
  • Adam Mitz
    Adam Mitz about 13 years
    OK, but I don't see why that's necessary when ./configure --enable-shared seems to work fine.
  • Adam Mitz
    Adam Mitz about 13 years
    What I've seen of the CMake debacle in Boost is that when the core devs don't use it and endorse it as the official build mechanism, it's not worth spending your time on. Maybe LLVM is different in that regard, but my attempt at a shared-lib build without CMake was successful.
  • ohmantics
    ohmantics about 13 years
    A few of the Apple engineers that work on LLVM use CMake to generate an Xcode 4 project. CMake also gets used by the handful of hopeless romantics that someday want Clang to be a drop-in replacement for MSVC. Other than that, everybody sensible uses the autoconf and make build system. (Apple's Build and Integration team's official released builds use the stuff in llvm/utils/buildit, which is also based on the autoconf/make stuff.)
  • Adam Mitz
    Adam Mitz about 13 years
    That sounds like an endorsement for autotools instead of CMake, unless I'm misunderstanding. I have to agree even though I'm no fan of autotools (it's OK as a user, I wouldn't want to touch it as a maintainer).
  • Tarantula
    Tarantula about 13 years
    1) CMake provides portability between different compilers, including gcc, visual studio, etc.. 2) My whole library is using cmake 3) Autotools = autohell 4) LLMV has support for cmake 5) I can integrate using the native llvm cmake module 6) There is no choice in this point of my project
  • Adam Mitz
    Adam Mitz about 13 years
    I think you're answering a different question. The question was why you need to build LLVM with CMake, not why you have decided to use CMake for your own project.
  • Tarantula
    Tarantula about 13 years
    Man, the only way to automatically install LLVM CMake modules is using CMake to build LLVM, and I need those modules for my library.
  • Adam Mitz
    Adam Mitz about 13 years
    I'll have to remember that next time I decide whether or not to use CMake. It seems to have this "infectiousness" property that I'd rather avoid.
  • Tarantula
    Tarantula about 13 years
    What "infectiousness" property ?
  • Adam Mitz
    Adam Mitz about 13 years
    It's infecting external projects -- just because you want to use CMake to build your own software, you're forced to (encouraged to? preferring to?) use it to build 3rd party software (LLVM).
  • ohmantics
    ohmantics about 13 years
    autotools was clearly forged in hell by sadists hell bent on increasing your build times through lack of parallelism and increased complexity. Perhaps they're fond of XKCD. Either way, the actual issue here is that the autotools build of LLVM is better maintained. For me, the killer is that the CMake build doesn't handle cross-compilers at all.
  • rubenvb
    rubenvb about 13 years
    @Adam: same thing goes for libtool, it also places .la files that are picked up by other projects. Dang man, give it a rest. CMake is better in some aspects, and autools is hell for some people (like me). At least the delivered CMake modules make it possible to "officially" detect the LLVM libraries, where autotools you need to conjure up the magic yourself.
  • Adam Mitz
    Adam Mitz about 13 years
    Again the argument is being changed instead of replied to. The question is /not/ if CMake is better in general. The question is how to build someone else's software: the way they recommend and endorse, or the way a vocal minority prefers?
  • Doug
    Doug about 12 years
    llvm.org/docs/CMake.html <-- Not part of the 2.8 documentation, but they do use cmake.
  • shevy
    shevy almost 7 years
    Adam Mitz - often you don't have a lot of choice. Gnome recently switched to meson and ninja, so you need to have these available; and mesa in particular requires a shared built of llvm. Please do not distract and instead help people. Tarantula has requested help and you are not helping him Adam Mitz.
  • shevy
    shevy almost 7 years
    Adam Mitz - although this is old, see the more recent situation "The LLVM project no longer supports building with configure & make." so configure does no longer work. They switched to cmake and cmake has awful syntax compared to GNU autoconfigure. Or can you easily find the equivalent of --enable-shared via cmake AND have this work consistently across ALL projects?