0

I am trying to compile code at runtime using libclang. I am giving ti deliberately malformed code to try to see how to print error messages.

To this effect I am calling clang_parseTranslationUnit2 on my faulty string. And sure enough it returns an error code but that is about it. I would like to get some form of error message, ideally similar to the errors you get when compiling through the terminal with clang.

Is this possible? I have searched the documentation and I am looking at the headers and I don't see anything of the sort.

Makogan
  • 8,208
  • 7
  • 44
  • 112
  • 1
    Seems like a likely candidate https://clang.llvm.org/doxygen/group__CINDEX__DIAG.html#gaf786e9688b9a685958e486cb81910924 – Alan Birtles Aug 29 '21 at 08:25
  • That function seems to take an already parsed compilation unit, but if the input is malformed you cannot create a unit in the first place :\ – Makogan Aug 30 '21 at 04:53
  • As far as I can see from the docs `clang_parseTranslationUnit2` will always give you back a translation unit – Alan Birtles Aug 30 '21 at 07:58
  • From the docs: > In case of an error this routine returns a NULL CXTranslationUnit, without further detailed error codes. https://clang.llvm.org/doxygen/group__CINDEX__TRANSLATION__UNIT.html – Makogan Aug 30 '21 at 17:00
  • thats from `clang_parseTranslationUnit`, you are calling `clang_parseTranslationUnit2`? Even for `clang_parseTranslationUnit` I assume it returns `NULL` if it can't parse the file at all e.g. can't open the file, not for compilation failures – Alan Birtles Aug 30 '21 at 17:03
  • Oh I see, that's silly of me, let me check it out. – Makogan Aug 30 '21 at 19:10

0 Answers0