如何在C+&#x2B中使用LLVM库XCode项目?
#include "llvm/ADT/STLExtras.h"
#include "llvm/IR/BasicBlock.h"
#include "llvm/IR/Constants.h"
#include "llvm/IR/DerivedTypes.h"
#include "llvm/IR/Function.h"
#include "llvm/IR/IRBuilder.h"
#include "llvm/IR/LLVMContext.h"
#include "llvm/IR/Module.h"
#include "llvm/IR/Type.h"
#include "llvm/IR/Verifier.h"
我尝试添加inclage文件夹(/opt/opt/opt/homebrew/homebrew/cellar/llvm /13.0.1_1/include
For Me)到Xcode中的标题搜索路径,它似乎有所作为,但我最终遇到了错误未定义的符号:llvm :: disableabibreakingchecks
,而数百个不同的警告。
我想要的就是能够在一个小的C ++项目中使用LLVM代码生成。有什么简单的方法吗?
I'm loosely following the tutorial to implement Kaleidoscope on the LLVM website, and I'm at the point where I need to actually use the LLVM library for code generation. I've installed LLVM 13 using homebrew (brew install llvm
), but I can't figure out how to use it in a c++ project in Xcode. I just get the error 'llvm/whatever/whatever' file not found
for every file I try to include:
#include "llvm/ADT/STLExtras.h"
#include "llvm/IR/BasicBlock.h"
#include "llvm/IR/Constants.h"
#include "llvm/IR/DerivedTypes.h"
#include "llvm/IR/Function.h"
#include "llvm/IR/IRBuilder.h"
#include "llvm/IR/LLVMContext.h"
#include "llvm/IR/Module.h"
#include "llvm/IR/Type.h"
#include "llvm/IR/Verifier.h"
I've tried adding the include folder (/opt/homebrew/Cellar/llvm/13.0.1_1/include
for me) to the header search paths in Xcode, which seems to do something but I end up with the error Undefined symbol: llvm::DisableABIBreakingChecks
, and hundreds of different warnings.
All I want is to be able to use LLVM code generation in a small c++ project. Is there any simple way to do this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我也在做那个教程。我会告诉您我如何工作,但是由于我不是LLVM专家,所以我不知道这是最好的方法。
我从源签出并构建了LLVM,如在这里描述。像您一样使用啤酒安装也应该很好。
接下来,我查看了他们在教程中给出的构建命令:
我可以从构建目录中运行
llvm-config
命令,它为我提供了以某种方式给Xcode提供的标志。我将那些
-i
路径放在header_search_paths
构建设置中,-L
路径libers> library_search_paths
中的路径。在XCode中,这些值是路径列表,因此您可以在没有-I
或-L
part的情况下添加路径。然后,我将-l </code>库参数放入
参数其他_ldflags
中,然后将-d
gragonmentseleth_cplusplusflags
。之后,它从Xcode编译并运行。我还没有将所有输出从
llvm-config
转换为Xcode build设置。例如,我对此一无所知:还有待观察,这是否以后会引起问题。
I'm also doing that tutorial. I'll tell you how I got it to work, but since I'm not an LLVM expert, I don't know if this is the best way.
I checked out and built LLVM from source, as described here. Installing with brew like you did should also work fine.
Next, I looked at the build command they give in the tutorial:
I can run that
llvm-config
command from my build directory and it gives me the flags that I need to somehow give to Xcode.I put those
-I
paths in theHEADER_SEARCH_PATHS
build setting, and the-L
path inLIBRARY_SEARCH_PATHS
. In Xcode those values are a list of paths, so you add the paths without the-I
or-L
part. I then put the-l
library arguments inOTHER_LDFLAGS
, and the-D
arguments inOTHER_CPLUSPLUSFLAGS
.After that, it compiled and ran from Xcode. I did not yet translate all of the output from
llvm-config
into Xcode build settings. For example, I did nothing about these:Remains to be seen if that will cause problems later.