missing libc++ headers in clang search path
RBogie opened this issue · comments
I'm currently trying to setup a docker image with a raspberry pi clang toolchain (And later also flutter (found this repo through your flutter_embedded repo)), but I'm running into a clang issue.
After succesfully building clang I'm trying a test build (Simply building a hello world) to see if the generated executables will run on the raspberry pi correctly. When I'm building a c application, this is the case. However, c++ headers are not found by clang++.
The smallest file to reproduce this is the following:
#include <cstdio>
int main() {}
This won't compile, with the error fatal error: 'cstdio' file not found
. Looking at the search paths, it is searching in the host's include dirs and the 'sdk/toolchain/lib/clang/7.0.1/include' directory.
If I manually search the sdk folder for the cstdio file, I find the following folders (Which are not searched):
./sdk/sysroot/usr/include/c++/6/cstdio
./sdk/sysroot/usr/include/c++/6/tr1/cstdio
./sdk/toolchain/lib/clang/7.0.1/arm-linux-gnueabihf/include/c++/v1/cstdio
The last one is the self compiled libcxx as far as I understand. However, this directory is not searched by clang. Manually adding it to the search path with -I will simply result in errors further down the line, with includes that are in the 'sdk/toolchain/lib/clang/7.0.1/arm-linux-gnueabihf' folder, etc.
Any clue on what the issue could be here?
The buildlog: buildlog.txt
(Since the environment is very reproducable because of docker, I also attached my
Dockerfile)
Hi,
Your first line of defense is get as much debugging info as you can.
Compiler output:
make VERBOSE=1
Linker output:
In cmake toolchain file, add this flag to the end of the linker flags
-v
Stare at that a bit, and if you're still stuck let's see some logs.
Also as a reference point you can see how I use this project in my other repo - flutter_embedded
The flutter_embedded build also fails, although with a different error (Since the install toolchain step in that repo tries to copy libc++.so that can't be found in the location it is looking in).
Looking further into the files, it seems that the install prefix for libcxx libcxxabi and libunwind (${TOOLCHAIN_DIR}/lib/clang/${LLVM_VER_DIR}/${TARGET_TRIPLE}) is incorrect. Checking the buildlog, everything is installed correctly to the given locations. However, these libs are not found by clang, since it is looking in a different location. On top of that, the location is also not expected by the flutter_embedded project, which is looking in ${TOOLCHAIN_DIR} instead.
Is there a reason why they have a different prefix than clang itself? For now I will be trying a build with the prefix being the same
Yes, it's broken at the moment, and haven't fixed it yet (have a new job). Perhaps a better example is looking at how I build the MRAA library, as it uses C++. I used two toolchain files. One for compiler, one for target. Look at the target one...
-DLLVM_TARGETS_TO_BUILD="ARM" -DBUILD_PLATFORM_RPI=ON -DBUILD_MRAA=ON
Hmmz, I completely overlooked the fact cmake manually adds include paths when using a toolchain file. That's why it wasn't working when manually compiling something on the commandline.
I'll close this. Thank you for the help!