Error when using CMake with LLVM

后端 未结 5 551
慢半拍i
慢半拍i 2020-12-19 07:07

So I\'m trying to build a toy compiler using LLVM and I\'d like to use CMake as my build system. I tried using the sample CMakeLists.txt from LLVM\'s website, but I encounte

相关标签:
5条回答
  • 2020-12-19 07:17

    I have encountered this issue today (2019/01/03), while working on [SO]: Linking LLVM causes gcov to fail - (@CristiFati's answer).

    Environment:

    • Ubtu 16 x64
    • cmake 3.5.1
    • gcc 5.4.0
    • llvm 3.8.0 (llvm-3.8-dev)

    There were 2 kinds of errors (in the .cmake files):

    • References to incorrect paths (version (3.8) missing):
      • To other .cmake files (via inclusion)
      • To libraries (.a, .so) and executables
    • References to non existing libraries and executables

    Without too much reading about the root cause, I fixed the cmake files under /usr/share/llvm-3.8/cmake. There are 2 of them:

    • LLVMConfig.cmake
    • LLVMExports-relwithdebinfo.cmake

    that need to be copied at the above location (don't forget to backup the existing files).
    The action requires sudo rights.

    I also tried to create a diff (unified) and upload it here, but it wouldn't fit due to size constraints, so I placed the files at [GitHub]: CristiFati/llvm_fixes - (3.8-ubtu-cmake) (check NOTES.md which contains almost the same info as this post).

    Note: I named all the new variables _CFATI_*, so that changes are easy to spot (e.g. if one deleted the original files). Feel free to rename them.

    0 讨论(0)
  • 2020-12-19 07:22

    AFAIK, this is a well-known bug in Ubuntu's packaging. The original issue still persists in llvm-3.8-dev on Ubuntu 16.04 see here and here.

    When attempting to fix LLVMExports.cmake by manually setting the import prefix

    set(_IMPORT_PREFIX "/usr/lib/llvm-3.8")
    

    CMake was able to find libLLVMSupport.a and other libraries. However, I was faced with the following issue

     The imported target "PollyISL" references the file
    
        "/usr/lib/llvm-3.8/lib/libPollyISL.a"
    
     but this file does not exist.  Possible reasons include:
    

    Surprisingly, library libPollyISL.a does not even exist in LLVM installation directory. Therefore, the problem is more than CMake config.

    To save time, build LLVM yourself from source and set LLVM_DIR env variable. See this tutorial.

    0 讨论(0)
  • 2020-12-19 07:27

    The easiest option is to install a version of LLVM that doesn't have that problem: the error disappeared for me after doing:

    apt-get remove llvm
    apt-get autoremove
    apt-get install llvm-3.9
    

    (Tested on Ubuntu 16.04.)

    0 讨论(0)
  • 2020-12-19 07:29

    In my case, installing the package 'llvm-dev' solved the problem.

    This installs the 3.8 version (in my case) but with different paths and locations than the 'llvm-3.8-dev' package.

    0 讨论(0)
  • 2020-12-19 07:40

    You need to fix LLVMExports-relwithdebinfo.cmake instead of LLVMExports.cmake.

    In /usr/share/llvm-3.8/cmake, you can find LLVMExports-relwithdebinfo.cmake

    Once you open the file, manually set the import prefix

      # Commands may need to know the format version.                                                                                                                                                        
      set(CMAKE_IMPORT_FILE_VERSION 1)                                                                                                                                                                       
      set(_IMPORT_PREFIX "/usr/lib/llvm-3.8")     
    

    And comment out all libraries related with -polly.

    # Import target "PollyISL" for configuration "RelWithDebInfo"                                                                                                                                               
    # set_property(TARGET PollyISL APPEND PROPERTY IMPORTED_CONFIGURATIONS RELWITHDEBINFO)                                                                                                                      
    # set_target_properties(PollyISL PROPERTIES                                                                                                                                                                 
    #   IMPORTED_LINK_INTERFACE_LANGUAGES_RELWITHDEBINFO "C"                                                                                                                                                    
    #   IMPORTED_LOCATION_RELWITHDEBINFO "${_IMPORT_PREFIX}/lib/libPollyISL.a"                                                                                                                                  
    #   )                                                                                                                                                                                                       
    #                                                                                                                                                                                                           
    # list(APPEND _IMPORT_CHECK_TARGETS PollyISL )                                                                                                                                                              
    # list(APPEND _IMPORT_CHECK_FILES_FOR_PollyISL "${_IMPORT_PREFIX}/lib/libPollyISL.a" )                                                                                                                      
    #                                                                                                                                                                                                           
    # # Import target "Polly" for configuration "RelWithDebInfo"                                                                                                                                                
    # set_property(TARGET Polly APPEND PROPERTY IMPORTED_CONFIGURATIONS RELWITHDEBINFO)                                                                                                                         
    # set_target_properties(Polly PROPERTIES                                                                                                                                                                    
    #   IMPORTED_LINK_INTERFACE_LANGUAGES_RELWITHDEBINFO "CXX"                                                                                                                                                  
    #   IMPORTED_LOCATION_RELWITHDEBINFO "${_IMPORT_PREFIX}/lib/libPolly.a"                                                                                                                                     
    #   )                                                                                                                                                                                                       
    #                                                                                                                                                                                                           
    # list(APPEND _IMPORT_CHECK_TARGETS Polly )                                                                                                                                                                 
    # list(APPEND _IMPORT_CHECK_FILES_FOR_Polly "${_IMPORT_PREFIX}/lib/libPolly.a" )                                                                                                                            
    #                                                                                                                                                                                                           
    # # Import target "LLVMPolly" for configuration "RelWithDebInfo"                                                                                                                                            
    # set_property(TARGET LLVMPolly APPEND PROPERTY IMPORTED_CONFIGURATIONS RELWITHDEBINFO)                                                                                                                     
    # set_target_properties(LLVMPolly PROPERTIES                                                                                                                                                                
    #   IMPORTED_LOCATION_RELWITHDEBINFO "${_IMPORT_PREFIX}/lib/LLVMPolly.so"                                                                                                                                   
    #   IMPORTED_NO_SONAME_RELWITHDEBINFO "TRUE"                                                                                                                                                                
    #   )                                                                                                                                                                                                       
    #                                                                                                                                                                                                           
    # list(APPEND _IMPORT_CHECK_TARGETS LLVMPolly )                                                                                                                                                             
    # list(APPEND _IMPORT_CHECK_FILES_FOR_LLVMPolly "${_IMPORT_PREFIX}/lib/LLVMPolly.so" )  
    

    then in /usr/lib/llvm-3.8/lib

    sudo ln -s ../../x86_64-linux-gnu/libLLVM-3.8.so.1 ./libLLVM-3.8.so.1  
    
    0 讨论(0)
提交回复
热议问题