我试图在用
Swift编写的Xcode项目中使用LLVM C API.为此,我松散地遵循指南
here,但遇到了麻烦.在编译步骤中,在Xcode中添加包含路径到构建设置后,我收到以下错误:
<unknown>:0: error: module 'LLVM_Backend.CodeGen.PBQP.math' requires feature 'cplusplus' /Users/freddy/Development/llvm-source/build/include/llvm/Support/DataTypes.h:35:10: note: submodule of top-level module 'LLVM_Backend' implicitly imported here #include <math.h> ^ <module-includes>:1:9: note: in file included from <module-includes>:1: #import "./Analysis.h" ^ /Users/freddy/Development/llvm-source/llvm/include/llvm-c/./Analysis.h:22:10: note: in file included from /Users/freddy/Development/llvm-source/llvm/include/llvm-c/./Analysis.h:22: #include "llvm-c/Types.h" ^ /Users/freddy/Development/llvm-source/llvm/include/llvm-c/Types.h:17:10: error: could not build module 'LLVM_Support_DataTypes' #include "llvm/Support/DataTypes.h" ^ /Users/freddy/Development/Xcode Projects/SwiftLLVMTest/SwiftLLVMTest/main.swift:10:8: error: could not build Objective-C module 'LLVM_C' import LLVM_C
-Xcc -D__STDC_CONSTANT_MACROS \ -Xcc -D__STDC_LIMIT_MACROS
但我不确定在构建设置中将它们放在哪里 – 将它们添加到’其他C标志’或’其他Swift标志’选项似乎没有做任何事情.
我该怎么做呢?
尝试通过使用
Homebrew运行brew install llvm来预安装LLVM.
注意:我强烈建议使用Swift包装器,如LLVMSwift,在这种情况下,您应该按照此处的安装说明进行操作.但如果您想自己直接访问LLVM,请继续阅读.
将/usr/local / opt / llvm / include添加到标题搜索路径,将/usr/local / opt / llvm / lib添加到项目所需目标下的库搜索路径“Build Settings”下:
并将/usr/local/opt/llvm/lib/libLLVM.dylib(在Finder中打开,打开-R’/usr/local/opt/llvm/lib/libLLVM.dylib’)拖到“链接的框架和库”下“一般“(并使其成为”必需“如图所示):
最后,创建一个Objective-C桥接头(steps 1-2 in this tutorial,如果您不确定如何)并包含您需要的任何头(例如,#include< llvm-c / Core.h>):
你们都准备好了!只需像在Swift代码中一样使用任何LLVM类.