morganstanley / hobbes

A language and an embedded JIT compiler
http://hobbes.readthedocs.io/
Apache License 2.0
1.16k stars 105 forks source link

wrong cxxabi.h selected if libcxxabi installed and gcc as compiler #425

Closed mo-xiaoming closed 2 years ago

mo-xiaoming commented 2 years ago

On ubuntu, if libcxxabi is installed, and gcc used as compiler, then there is a chance that an compilation error will be thrown

../include/hobbes/lang/preds/subtype/obj.H:52:23: error: ‘__si_class_type_info’ in namespace ‘__cxxabiv1’ does not name a type; did you mean ‘__class_type_info’?
   52 |   typedef __cxxabiv1::__si_class_type_info  si_class_type;

Basically, it is about wrong cxxabi.h in Obj.H gets included

This is caused by search order of include path, llvm path will be searched before system default folder, and in llvm path, there is a cxxabi.h installed by libcxxabi, so this one will be used instead of the one with gcc, thus compilation fails

To solve this problem, at least when compiling with gcc, llvm path has to be searched after system default path, -idirafter is the only solution I got

without -idirafter

#include <...> search starts here:
 ../include
 /usr/lib/llvm-10/include                      # <-- wrong cxxabi.h
 /usr/include/c++/9                             # should be this one
...
End of search list.

with -idirafter

#include <...> search starts here:
 ../include
 /usr/include/c++/9                            # correct order
...
 /usr/lib/llvm-10/include                     # wrong one will not be used
End of search list.