我想在我的演示应用程序中使用LLVM / Clang API将源文件编译为LLVM IR,而没有clang
可执行调用。似乎Driver
仍然使用可执行文件来执行Compilation
(我已经使用了稍加修改的example)
string clangPath = "clang";
string inputPath = "../test/hello_world.cpp";
string outputPath = "hello_world.ll";
// "clang -S -emit-llvm ../test/hello_world.cpp -v"
vector<const char *> args;
args.push_back(clangPath.c_str());
args.push_back("-S");
args.push_back("-emit-llvm");
args.push_back(inputPath.c_str());
args.push_back("-v");
// ...
正如您所看到的,它打印动作并且编译似乎需要clang
可执行路径:
MBA-Anton:build asmirnov$ ./clang_ir
Starting ----
making driver
making compilation
clang version 3.4 (branches/release_34 198679)
Target: x86_64-apple-darwin13.2.0
Thread model: posix
printing actions:
0: input, "../test/hello_world.cpp", c++
1: preprocessor, {0}, c++-cpp-output
2: compiler, {1}, ir
3: bind-arch, "x86_64", {2}, ir
Done ----
"clang" -cc1 -triple x86_64-apple-macosx10.9.0 -emit-llvm -disable-free -main-file-name hello_world.cpp -mrelocation-model pic -pic-level 2 -mdisable-fp-elim -masm-verbose -munwind-tables -target-cpu core2 -target-linker-version 224.1 -v -coverage-file /Users/asmirnov/Documents/dev/src/clang_jni/mac/build/hello_world.ll -resource-dir ../lib/clang/3.4 -stdlib=libc++ -fdeprecated-macro -fdebug-compilation-dir /Users/asmirnov/Documents/dev/src/clang_jni/mac/build -ferror-limit 19 -fmessage-length 100 -stack-protector 1 -mstackrealign -fblocks -fobjc-runtime=macosx-10.9.0 -fencode-extended-block-signature -fcxx-exceptions -fexceptions -fdiagnostics-show-option -fcolor-diagnostics -vectorize-slp -o hello_world.ll -x c++ ../test/hello_world.cpp
error: unable to execute command: Executable "clang" doesn't exist!
它真的需要clang路径吗?如何通过LLVM / Clang API编译到LLVM IR而没有可执行调用?如果它不适用于当前API,我如何修改API以使用静态库而不是可执行文件?