C++ Cross Compiling using FreeBSD Clang

I have a project that involves frequent cross compilation to aarch64 Linux using clang (and lld). This is linked / built against a sysroot for aarch64 Linux.

A simple test program builds fine on Linux and macOS (using LLVM clang not Apple clang as it does not support lld), however it fails to build on FreeBSD. It fails with the following output

Code:
In file included from /home/myuser/Projects/minexample/src/main.cpp:2:
In file included from /home/myuser/sysroot/aarch64/usr/lib/gcc/aarch64-linux-gnu/8/../../../../include/c++/8/iostream:39:
In file included from /home/myuser/sysroot/aarch64/usr/lib/gcc/aarch64-linux-gnu/8/../../../../include/c++/8/ostream:38:
In file included from /home/myuser/sysroot/aarch64/usr/lib/gcc/aarch64-linux-gnu/8/../../../../include/c++/8/ios:38:
In file included from /home/myuser/sysroot/aarch64/usr/lib/gcc/aarch64-linux-gnu/8/../../../../include/c++/8/iosfwd:40:
In file included from /home/myuser/sysroot/aarch64/usr/lib/gcc/aarch64-linux-gnu/8/../../../../include/c++/8/bits/postypes.h:40:
In file included from /home/myuser/sysroot/aarch64/usr/lib/gcc/aarch64-linux-gnu/8/../../../../include/c++/8/cwchar:44:
/home/myuser/sysroot/aarch64/usr/include/wchar.h:35:10: fatal error: 'stddef.h' file not found
#include <stddef.h>
         ^~~~~~~~~~
1 error generated.

My understanding is that stddef.h is provided by the compiler (not system / sysroot). On non-FreeBSD systems, this seems to be located in clang's "resource-dir". For example, on a mac using LLVM clang:
Code:
find $(clang -print-resource-dir) | grep "stddef\.h"
/usr/local/Cellar/llvm/17.0.4/lib/clang/17/include/stddef.h

However, on FreeBSD this same command shows no such file in the resource dir (/usr/lib/clang/14.0.5). I've tested with llvm17 package too (still no such header in resource dir).

It seems that this file is in /usr/include on FreeBSD (combining of compiler headers and system headers?).

Unfortunately, this doesn't seem to be solvable by adding `/usr/include` as an include directory or changing the resource directory to `/usr/` (as this results in the compiler finding FreeBSD system headers instead of the ones for the target system in the sysroot).

Am I correct that FreeBSD mixes system and compiler headers? If so, is there way to get around this issue using FreeBSD clang or would I have to build LLVM clang from source?
 
Back
Top