将CMake与LLVM一起使用时出错

时间:2016-07-03 15:38:43

标签: c++ ubuntu cmake llvm

所以我正在尝试使用LLVM构建一个玩具编译器,我想使用CMake作为我的构建系统。我尝试使用LLVM网站上的sample CMakeLists.txt,但在运行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)

当我去调查问题时,我发现我系统上的路径实际上是/usr/share/llvm-3.8/。当我尝试将路径更改为/usr/share/llvm/时,我得到了另一个错误:

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.

我真的不是CMake如何工作的专家,所以我不确定从哪里开始。我正在运行Ubuntu 16.04,我尝试通过各种不同的软件包安装LLVM,结果相同。这是Ubuntu包装系统的问题,还是我能解决的问题?

5 个答案:

答案 0 :(得分:3)

AFAIK,这是Ubuntu包装中一个众所周知的错误。原始问题仍然存在于Ubuntu 16.04上的llvm-3.8-dev中,请参阅herehere

尝试通过手动设置导入前缀

来修复LLVMExports.cmake
set(_IMPORT_PREFIX "/usr/lib/llvm-3.8")

CMake能够找到libLLVMSupport.a和其他库。但是,我遇到了以下问题

 The imported target "PollyISL" references the file

    "/usr/lib/llvm-3.8/lib/libPollyISL.a"

 but this file does not exist.  Possible reasons include:

令人惊讶的是,库libPollyISL.a甚至不存在于LLVM安装目录中。因此,问题不仅仅是CMake配置。

为了节省时间,请自己从源代码构建LLVM并设置LLVM_DIR env变量。见tutorial

答案 1 :(得分:1)

您需要修复LLVMExports-relwithdebinfo.cmake而不是LLVMExports.cmake

在/usr/share/llvm-3.8/cmake中,您可以找到LLVMExports-relwithdebinfo.cmake

打开文件后,手动设置导入前缀

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

并注释掉与-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" )  

然后在/usr/lib/llvm-3.8/lib

sudo ln -s ../../x86_64-linux-gnu/libLLVM-3.8.so.1 ./libLLVM-3.8.so.1  

答案 2 :(得分:0)

在我的情况下,安装软件包' llvm-dev'解决了这个问题。

这将安装3.8版本(在我的情况下),但路径和位置不同于' llvm-3.8-dev'封装

答案 3 :(得分:0)

我今天在[SO]: Linking LLVM causes gcov to fail - (@CristiFati's answer)上工作时遇到了这个问题( 2019/01/03 )。

环境:

  • Ubtu 16 x64
  • cmake 3.5.1
  • gcc 5.4.0
  • llvm 3. 8 .0 llvm-3.8-dev

有2种错误(在 .cmake 文件中):

  • 对不正确路径的引用(缺少版本( 3.8 )):
    • 到其他 .cmake 文件(通过包含)
    • 到库( .a .so )和可执行文件
  • 对不存在的库和可执行文件的引用

在没有过多了解根本原因的情况下,我修复了 /usr/share/llvm-3.8/cmake 下的 cmake 文件。其中有2个:

  • LLVMConfig.cmake
  • LLVMExports-relwithdebinfo.cmake

需要复制到上述位置的文件(不要忘记备份现有文件)。
该操作需要 sudo 权限。

我还尝试创建一个 diff (统一)并将其上传到此处,但是由于大小限制,它不适合,因此我将文件放置在 [GitHub]: CristiFati/llvm_fixes - (3.8-ubtu-cmake) (选中 NOTES.md ,其中包含与此信息几乎相同的信息)。

注意:我将所有新变量命名为 _CFATI _ * ,这样很容易发现更改(例如,如果删除了原始文件)。随时重命名它们。

答案 4 :(得分:0)

最简单的选择是安装一个没有问题的LLVM版本:这样做后,错误对我消失了

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

(在Ubuntu 16.04上测试。)