Issue |
64237
|
Summary |
errors when using `clang-repl` interpreter in project on mac
|
Labels |
|
Assignees |
|
Reporter |
samuelpmish
|
I'm using `clang-repl` to embed a C++ interpreter in a library to enable JIT compilation, and I've been really happy with the results so far. However, when building this project on a mac, the JIT compiler is failing on even trivial programs. For example, creating the interpreter with
```cpp
std::vector<const char *> flags = {
"-march=native", "-Xclang", "-emit-llvm-only",
};
auto CI = llvm::cantFail(IncrementalCompilerBuilder::create(flags));
interpreter = llvm::cantFail(Interpreter::create(std::move(CI)));
```
and using it to compile
```cpp
#include <functional>
```
runs into errors
```sh
In file included from <<< inputs >>>:1:
In file included from input_line_0:2:
In file included from /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX13.3.sdk/usr/include/c++/v1/functional:510:
In file included from /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX13.3.sdk/usr/include/c++/v1/__functional/bind.h:17:
In file included from /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX13.3.sdk/usr/include/c++/v1/tuple:224:
In file included from /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX13.3.sdk/usr/include/c++/v1/iosfwd:99:
In file included from /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX13.3.sdk/usr/include/c++/v1/__mbstate_t.h:29:
In file included from /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX13.3.sdk/usr/include/c++/v1/wchar.h:123:
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX13.3.sdk/usr/include/wchar.h:89:10: fatal error: 'stdarg.h' file not found
#include <stdarg.h>
^~~~~~~~~~
```
that aren't encountered when compiling with the same file with `clang++` from the same LLVM installation. I've tried comparing the include search paths in each case by adding "-v" to the compilation flags and comparing the results.
clang-repl output when including "-v"
```
#include "..." search starts here:
#include <...> search starts here:
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX13.3.sdk/usr/include/c++/v1
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX13.3.sdk/usr/include
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX13.3.sdk/System/Library/Frameworks (framework directory)
```
clang++ output when including "-v"
```
#include "..." search starts here:
#include <...> search starts here:
/opt/homebrew/opt/llvm/bin/../include/c++/v1
/opt/homebrew/Cellar/llvm/16.0.6/lib/clang/16/include
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX13.3.sdk/usr/include
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX13.3.sdk/System/Library/Frameworks (framework directory)
```
The obvious difference was that the first include search paths were different, so I tried manually specifying those paths to the interpreter,
```cpp
std::vector<const char *> flags = {
"-march=native", "-Xclang", "-emit-llvm-only",
"-isystem", "/opt/homebrew/Cellar/llvm/16.0.6/lib/clang/16/include",
"-I", "/opt/homebrew/opt/llvm/bin/../include/c++/v1"
};
```
and that does make the first two paths agree with the ones shown by `clang++ -v ...`:
```
#include "..." search starts here:
#include <...> search starts here:
/opt/homebrew/opt/llvm/bin/../include/c++/v1
/opt/homebrew/Cellar/llvm/16.0.6/lib/clang/16/include
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX13.3.sdk/usr/include/c++/v1
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX13.3.sdk/usr/include
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX13.3.sdk/System/Library/Frameworks (framework directory)
End of search list.
```
but the `clang-repl` interpreter still emits a long list of errors when trying to compile the `#include <functional>` directive:
```sh
In file included from /opt/homebrew/opt/llvm/bin/../include/c++/v1/functional:503:
In file included from /opt/homebrew/opt/llvm/bin/../include/c++/v1/__algorithm/search.h:14:
In file included from /opt/homebrew/opt/llvm/bin/../include/c++/v1/__algorithm/iterator_operations.h:15:
In file included from /opt/homebrew/opt/llvm/bin/../include/c++/v1/__iterator/advance.h:26:
In file included from /opt/homebrew/opt/llvm/bin/../include/c++/v1/cstdlib:87:
/opt/homebrew/opt/llvm/bin/../include/c++/v1/stdlib.h:150:34: error: unknown type name 'ldiv_t'
inline _LIBCPP_INLINE_VISIBILITY ldiv_t div(long __x, long __y) _NOEXCEPT {
^
/opt/homebrew/opt/llvm/bin/../include/c++/v1/stdlib.h:151:12: error: no member named 'ldiv' in the global namespace
return ::ldiv(__x, __y);
~~^
/opt/homebrew/opt/llvm/bin/../include/c++/v1/stdlib.h:154:34: error: unknown type name 'lldiv_t'
inline _LIBCPP_INLINE_VISIBILITY lldiv_t div(long long __x,
^
/opt/homebrew/opt/llvm/bin/../include/c++/v1/stdlib.h:156:12: error: no member named 'lldiv' in the global namespace
```
There are a handful of similar issues in `xeus-cling`, like
https://github.com/jupyter-xeus/xeus-cling/issues/403
https://github.com/jupyter-xeus/xeus-cling/issues/412
Does anyone know how to configure a `clang-repl` interpreter for use in projects outside of the LLVM source tree, on mac?
Is it possible to make the default `clang-repl` configuration mimic the implicit assumptions of `clang++` from the same LLVM build?
---------
llvm version 16.0.6 installed with homebrew
m1 mac running 13.4
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs