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?
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 prefixCMake was able to find
libLLVMSupport.a
and other libraries. However, I was faced with the following issueSurprisingly, 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.
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.
I have encountered this issue today (2019/01/03), while working on [SO]: Linking LLVM causes gcov to fail - (@CristiFati's answer).
Environment:
There were 2 kinds of errors (in the .cmake files):
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:
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.
You need to fix
LLVMExports-relwithdebinfo.cmake
instead ofLLVMExports.cmake
.In /usr/share/llvm-3.8/cmake, you can find
LLVMExports-relwithdebinfo.cmake
Once you open the file, manually set the import prefix
And comment out all libraries related with -polly.
then in
/usr/lib/llvm-3.8/lib