Error when using CMake with LLVM

11,121

Solution 1

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.

Solution 2

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.)

Solution 3

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  
Share:
11,121
AUD_FOR_IUV
Author by

AUD_FOR_IUV

My name is [REDACTED], and I study Computer Science at the University of North Carolina at Chapel Hill. By night, I weave untold technological wonders in the dark of my room for no one to see. By day, I go back and fix the countless bugs in the resulting garbage. In my spare time, I like to learn about how computers work from the transistors up and make fun of web devs for doing what I never could.

Updated on June 11, 2022

Comments

  • AUD_FOR_IUV
    AUD_FOR_IUV almost 2 years

    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 encounter the following error when running cmake:

    CMake Error at /usr/share/llvm-3.8/cmake/LLVMConfig.cmake:178  (include):
      include could not find load file:
    
        /usr/share/llvm/cmake/LLVMExports.cmake
    Call Stack (most recent call first):
      CMakeLists.txt:4 (find_package)
    
    
    CMake Error at /usr/share/llvm-3.8/cmake/LLVMConfig.cmake:181 (include):
      include could not find load file:
    
        /usr/share/llvm/cmake/LLVM-Config.cmake
    Call Stack (most recent call first):
      CMakeLists.txt:4 (find_package)
    

    When I went to go investigate the problem, I discovered that the path on my system is actually /usr/share/llvm-3.8/. When I tried changing the path to /usr/share/llvm/ like it expects, I get another error:

    CMake Error at /usr/share/llvm/cmake/LLVMExports.cmake:1034 (message):
      The imported target "LLVMSupport" references the file
    
         "/usr/lib/libLLVMSupport.a"
    
      but this file does not exist.  Possible reasons include:
    
      * The file was deleted, renamed, or moved to another location.
    
      * An install or uninstall procedure did not complete successfully.
    
      * The installation package was faulty and contained
    
         "/usr/share/llvm/cmake/LLVMExports.cmake"
    
      but not all the files it references.
    

    I'm not really an expert on how exactly CMake works, so I'm not sure where to go from here. I'm running Ubuntu 16.04, and I've tried installing LLVM through various different packages with the same results. Is this a problem with Ubuntu's packaging system, or is something that I can fix?