使用 CMake 遵循 Pass 教程时出现内部 LLVM 语法错误

Internal LLVM syntax errors when following Pass tutorial using CMake

我正在尝试按照教程 here for developing a "Hello, World" LLVM pass - I am using the guidelines linked by that tutorial here 在 LLVM 源目录中执行此操作。但是,当我尝试按照本教程进行操作时,CMake 报告了 LLVM 本身内部的许多错误。

我有以下目录结构:

HelloWorld/ CMakeLists.txt HelloWorld/ CMakeLists.txt HelloWorld.cpp

我的HelloWorld.cpp和两个CMakeLists.txt是直接从上面的教程link复制粘贴过来的。

I 运行 CMake HelloWorld 它成功生成了 CMake 配置。然而,当我运行make。我从 LLVM 代码库本身收到大量错误报告。

[ 50%] Building CXX object CMakeFiles/LLVMPassName.dir/Vectorize.cpp.o
In file included from /Volumes/andromeda/HelloWorld/HelloWorld.cpp:1:
In file included from /usr/local/Cellar/llvm/3.6.2/include/llvm/Pass.h:377:
In file included from /usr/local/Cellar/llvm/3.6.2/include/llvm/PassSupport.h:27:
In file included from /usr/local/Cellar/llvm/3.6.2/include/llvm/PassRegistry.h:20:
In file included from /usr/local/Cellar/llvm/3.6.2/include/llvm-c/Core.h:18:
In file included from /usr/local/Cellar/llvm/3.6.2/include/llvm-c/Support.h:17:
/usr/local/Cellar/llvm/3.6.2/include/llvm/Support/DataTypes.h:57:3: error: "Must #define
      __STDC_LIMIT_MACROS before #including Support/DataTypes.h"
# error "Must #define __STDC_LIMIT_MACROS before #including Support/DataTypes.h"
  ^
/usr/local/Cellar/llvm/3.6.2/include/llvm/Support/DataTypes.h:61:3: error: "Must #define
      __STDC_CONSTANT_MACROS before "         "#including Support/DataTypes.h"
# error "Must #define __STDC_CONSTANT_MACROS before " \

这个列表还在继续,所有这些都涉及 LLVM 头文件中的错误。这是使用 Homebrew 全新安装的 LLVM。为了让 link 正常工作,我必须将 CPLUS_INCLUDE_PATH 设置为 LLVM 的 Homebrew 包含目录。

我的第一个想法是 CMake 试图使用不同的编译器(Clang 与 GCC,反之亦然),但设置 CMAKE_CXX_COMPILER 指向我的 clangg++ 安装没有帮助。

有没有人知道这里可能出现的问题?


按照@oak 在评论中提供的 link 进行操作后,我能够摆脱前两个 Support/DataType 错误。但是,许多错误仍然存​​在。

In file included from /usr/local/Cellar/llvm/3.6.2/include/llvm/Pass.h:377:
In file included from /usr/local/Cellar/llvm/3.6.2/include/llvm/PassSupport.h:27:
In file included from /usr/local/Cellar/llvm/3.6.2/include/llvm/PassRegistry.h:21:
/usr/local/Cellar/llvm/3.6.2/include/llvm/ADT/DenseMap.h:543:63: error: a space is required
      between consecutive right angle brackets (use '> >')
          typename BucketT = detail::DenseMapPair<KeyT, ValueT>>
                                                              ^
/usr/local/Cellar/llvm/3.6.2/include/llvm/ADT/DenseMap.h:694:63: error: a space is required
      between consecutive right angle brackets (use '> >')
          typename BucketT = detail::DenseMapPair<KeyT, ValueT>>

因此,经过大量研究后发现,LLVM 和 CMake 支持源外构建的方式存在不一致。 LLVM 二进制文件是用 -fno-rtti 构建的,因此 CMake 会抱怨缺少符号,除非它在编译 LLVM pass 时也使用 -fno-rtti

我通过将 SET(CMAKE_CXX_FLAGS "-Wall -fno-rtti") 添加到最内层目录中的 CMakeLists.txt 文件来解决所有问题(包括由 Oak 提出的临时修复解决的问题)。

这也是受 Whosebug 上的 question 启发。