c++ - 将 CMake 与 LLVM 一起使用时出错

标签 c++ ubuntu cmake llvm

所以我正在尝试使用 LLVM 构建一个玩具编译器,并且我想使用 CMake 作为我的构建系统。我尝试使用 sample CMakeLists.txt来自 LLVM 的网站,但在运行 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 打包系统的问题,还是我可以解决的问题?

最佳答案

据我所知,这是 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 环境变量。看这个tutorial .

关于c++ - 将 CMake 与 LLVM 一起使用时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38171543/

相关文章:

c++ - 包含对象指针的 STL 堆

c++ - PInvoke 返回带有二维数组的结构

c++ - 指针之间的转换运算符

git 状态不能与 Virtualbox 共享文件夹一起正常工作

cmake - 链接库时为linux和windows创造条件

c++ - boost::asio 阅读问题

linux - 使用搜索和替换清理感染 c3284d 病毒的服务器

python - 属性错误 : 'Settings' object has no attribute 'MERCHANT_SETTINGS'

c++ - cmake 层次结构 zlib、libpng 和我自己的应用程序

gcc - 如何使用 gcc 在 CMake 中正确设置可见性属性?