Error using CMake with LLVM

So, I'm trying to create a toy compiler using LLVM, and I would like to use CMake as my build system. I tried using the CMakeLists.txt sample from the LLVM website, but when cmake started:

 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 investigate the problem, I found that the path on my system is actually /usr/share/llvm-3.8/ . When I tried to change the path to /usr/share/llvm/ as 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 very good at how CMake works, so I'm not sure where to go from here. I am running Ubuntu 16.04 and I was trying to install LLVM through various packages with the same results. Is this a problem with the Ubuntu packaging system or something that I can fix?

+6
source share
6 answers

AFAIK, this is a known bug in Ubuntu packaging. The original problem is still persisting in llvm-3.8-dev on Ubuntu 16.04, see here and.

When trying 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 ran into the following problem

  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, the libPollyISL.a library does not even exist in the LLVM installation directory. Therefore, the problem is greater than the CMake configuration.

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

+4
source

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 the libraries associated 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 
+1
source

The easiest option is to install the LLVM version in which there is no such problem: the error disappeared after I did:

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

(Tested on Ubuntu 16.04.)

+1
source

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

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

0
source

I ran into this problem today ( 2019/01/03 ) when I was working on [SO]: LLVM binding causes gcov - to crash (@CristiFati answer) .

Wednesday:

  • 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 .cmake files):

  • Links to wrong paths (version (3.8) is missing):
    • For other .cmake files (via inclusion)
    • To libraries (.a, .so) and executables
  • Links to nonexistent libraries and executables

Not reading too much about the reasons, I fixed the cmake files in /usr/share/llvm-3.8/cmake . There are 2 of them:

  • LLVMConfig.cmake
  • LLVMExports-relwithdebinfo.cmake

it must be copied to the above location ( do not forget to backup existing files ).
Action requires sudo privilege.

I also tried to create a diff (unified) and load it here, but it does not fit due to size restrictions, so I put the files in [GitHub]: CristiFati / llvm_fixes - (3.8-ubtu-cmake) (check NOTES.md, which contains almost the same information as this post).

Note : I named all the new _CFATI_ * variables, so changes are easy to detect (for example, if one deleted the source files). Feel free to rename them.

0
source
  LLVM INSTALLATION STEPS ----------------------- 

Prerequisites for the LLVM compiler:

  OPERATING SYSTEM : Ubuntu 16.04 LTS RAM : Minimum 16GB to 32GB SWAP MEMORY : Minimum 10GB to 20GB MEMORY NEEDED : Minimum 70GB 

Install CMake version 3.5.1:

  $sudo apt install cmake 

Steps to Install the LLVM Compiler

Step 1: #download llvm from https://github.com/llvm/llvm-project/releases/download/llvmorg-8.0.1/llvm-8.0.1.src.tar.xz

 #download clang from https://github.com/llvm/llvm-project/releases/download/llvmorg-8.0.1/cfe-8.0.1.src.tar.xz #extract files into folders: tar -xf cfe-8.0.1.src.tar.xz tar -xf llvm-8.0.1.src.tar.xz #change directory names to llvm8 and clang mv cfe-8.0.1.src clang 

mv llvm-8.0.1.src llvm8

Step 2: # change the current working directory to llvm_source_directory, here it will be llvm8

 $cd llvm8 ##create build directory $mkdir build ##change pwd to build directory $cd build #Build (PATH =/llvm8/build) #execute following command in build directory: 

$ cmake -DLLVM_ENABLE_PROJECTS = clang -G "Makeix Unix Files" ../

Step 3: #execute make command in pwd:

/ llvm8 / build $ make

Step 4: # after 100% of the build process, run the following command in the build directory:

 $sudo make install 

$ sudo reboot

Step 5: # after installation, restart the system!

 #for checking llvm installation type $llvm-config --version #it shows 8.0.1 $clang --version #it shows 8.0.1 
0
source

All Articles