[cfe-dev] Running clang programmatically
Stefan Seefeld
stefan.seefeld at gmail.com
Tue Mar 16 21:10:16 PDT 2010
Hello,
I have some trouble invoking clang_createTranslationUnitFromSourceFile.
Here is the sequence of functions I use. (Note that I assembled that
from various comments in the code, and may likely have missed some
important bits):
// excludeDeclsFromPCH = 1, displayDiagnostics=1
CXIndex idx = clang_createIndex(1, 1);
char const *args[] = { "-Xclang"};
CXTranslationUnit TU = clang_createTranslationUnitFromSourceFile(idx,
input_file,
1, args, 0, 0);
clang_visitChildren(clang_getTranslationUnitCursor(TU), translate, 0);
clang_disposeTranslationUnit(TU);
clang_disposeIndex(idx);
This results in an error output, plus a subsequent segfault:
error: unable to handle compilation, expected exactly one compiler job
in ' "/usr/local/bin/clang" "-cc1" "-triple" "x86_64-unknown-linux-gnu"
"-S" "-disable-free" "-main-file-name" "test.cc" "-mrelocation-model"
"static" "-mdisable-fp-elim" "-mconstructor-aliases" "-munwind-tables"
"-target-cpu" "x86-64" "-resource-dir" "/lib/clang/1.1"
"-fmessage-length" "183" "-fexceptions" "-fgnu-runtime"
"-fdiagnostics-show-option" "-fcolor-diagnostics" "-fsyntax-only" "-o"
"/tmp/cc-GyUGlM.s" "-x" "c++" "/home/stefan/projects/Synopsis/test.cc";
"/usr/bin/gcc" "-Xclang" "-fsyntax-only" "-c" "-m64" "-o"
"/tmp/cc-fWJsot.o" "-x" "assembler" "/tmp/cc-GyUGlM.s"; "/usr/bin/gcc"
"-Xclang" "-fsyntax-only" "-m64" "-o" "a.out" "/tmp/cc-fWJsot.o"; '
My questions:
1) Is the function call sequence above (approximately) correct ? (If
not, what is wrong ?)
2) Where is the current error emitted, and how may I intercept it
programmatically ?
3) What is the error trying to tell me ?
Thanks for helping me getting started with CLang !
Stefan
--
...ich hab' noch einen Koffer in Berlin...
More information about the cfe-dev
mailing list