如何在C+&#x2B中使用LLVM库XCode项目?

发布于 2025-01-20 01:21:59 字数 890 浏览 1 评论 0原文

我很松散地关注教程,以在llvm网站上实现万花筒m在我需要实际使用LLVM库进行代码生成的点。我已经使用HomeBrew(brew install llvm)安装了LLVM 13,但是我不知道如何在Xcode的C ++项目中使用它。我只收到错误'llvm/whything/whyt whting'找不到我尝试包含的文件的文件

#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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

谁的新欢旧爱 2025-01-27 01:21:59

我也在做那个教程。我会告诉您我如何工作,但是由于我不是LLVM专家,所以我不知道这是最好的方法。

我从源签出并构建了LLVM,如在这里描述。像您一样使用啤酒安装也应该很好。

接下来,我查看了他们在教程中给出的构建命令:

clang++ -g -O3 toy.cpp `llvm-config --cxxflags --ldflags --system-libs --libs core` 
        -o toy

我可以从构建目录中运行llvm-config命令,它为我提供了以某种方式给Xcode提供的标志。

> bin/llvm-config --cxxflags --ldflags --system-libs --libs core 

-I/Users/rob/Foo/llvm-project/llvm/include 
-I/Users/rob/Foo/llvm-project/build/include 
-std=c++14 -fno-exceptions -fno-rtti 
-D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS

-L/Users/rob/Foo/llvm-project/build/lib 
-Wl,-search_paths_first -Wl,-headerpad_max_install_names

-lLLVMCore -lLLVMRemarks -lLLVMBitstreamReader 
-lLLVMBinaryFormat -lLLVMSupport -lLLVMDemangle

-lm -lz -lcurses -lxml2

我将那些-i路径放在header_search_paths构建设置中,-L路径libers> library_search_paths中的路径。在XCode中,这些值是路径列表,因此您可以在没有-I-L part的情况下添加路径。然后,我将-l <​​/code>库参数放入其他_ldflags中,然后将-d gragonments参数eleth_cplusplusflags

之后,它从Xcode编译并运行。我还没有将所有输出从llvm-config转换为Xcode build设置。例如,我对此一无所知:

-std=c++14 -fno-exceptions -fno-rtti
-Wl,-search_paths_first -Wl,-headerpad_max_install_names

还有待观察,这是否以后会引起问题。

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:

clang++ -g -O3 toy.cpp `llvm-config --cxxflags --ldflags --system-libs --libs core` 
        -o toy

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.

> bin/llvm-config --cxxflags --ldflags --system-libs --libs core 

-I/Users/rob/Foo/llvm-project/llvm/include 
-I/Users/rob/Foo/llvm-project/build/include 
-std=c++14 -fno-exceptions -fno-rtti 
-D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS

-L/Users/rob/Foo/llvm-project/build/lib 
-Wl,-search_paths_first -Wl,-headerpad_max_install_names

-lLLVMCore -lLLVMRemarks -lLLVMBitstreamReader 
-lLLVMBinaryFormat -lLLVMSupport -lLLVMDemangle

-lm -lz -lcurses -lxml2

I put those -I paths in the HEADER_SEARCH_PATHS build setting, and the -L path in LIBRARY_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 in OTHER_LDFLAGS, and the -D arguments in OTHER_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:

-std=c++14 -fno-exceptions -fno-rtti
-Wl,-search_paths_first -Wl,-headerpad_max_install_names

Remains to be seen if that will cause problems later.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文