Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
I'm currently trying to cross-compile libc++ (the C++ standard library for clang) to be able to cross-compile compiler-rt, which in turn should make me able to cross compile programs to run in my kernel's userspace.
-- The C compiler identification is Clang 10.0.0
-- The CXX compiler identification is Clang 10.0.0
-- The ASM compiler identification is Clang
-- Found assembler: /bin/clang
-- Check for working C compiler: /bin/clang
-- Check for working C compiler: /bin/clang -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /bin/clang++
-- Check for working CXX compiler: /bin/clang++ -- broken
CMake Error at /usr/share/cmake-3.16/Modules/CMakeTestCXXCompiler.cmake:53 (message):
The C++ compiler
"/bin/clang++"
is not able to compile a simple test program.
It fails with the following output:
Change Dir: /home/llenotre/Desktop/dev/gcc_maestro/llvm/build/CMakeFiles/CMakeTmp
Run Build Command(s):/bin/ninja cmTC_1a17f && [1/2] Building CXX object CMakeFiles/cmTC_1a17f.dir/testCXXCompiler.cxx.o
[2/2] Linking CXX executable cmTC_1a17f
FAILED: cmTC_1a17f
: && /bin/clang++ --target=i686-unknown-linux-musl CMakeFiles/cmTC_1a17f.dir/testCXXCompiler.cxx.o -o cmTC_1a17f && :
/bin/ld: skipping incompatible /bin/../lib/gcc/x86_64-linux-gnu/9/libstdc++.so when searching for -lstdc++
/bin/ld: skipping incompatible /bin/../lib/gcc/x86_64-linux-gnu/9/libstdc++.a when searching for -lstdc++
/bin/ld: cannot find -lstdc++
clang: error: linker command failed with exit code 1 (use -v to see invocation)
ninja: build stopped: subcommand failed.
CMake will not be able to correctly generate this project.
Call Stack (most recent call first):
CMakeLists.txt:3 (project)
-- Configuring incomplete, errors occurred!
See also "/home/llenotre/Desktop/dev/gcc_maestro/llvm/build/CMakeFiles/CMakeOutput.log".
See also "/home/llenotre/Desktop/dev/gcc_maestro/llvm/build/CMakeFiles/CMakeError.log".
And I just can't figure out why compiling libc++ seems to require the standard C++ library
Cross compiling LLVM is an absolute nightmare. The problem with what you're doing is that you're telling the build system to build libc++ with the host the same command line as the programs like clang. This won't work because we need to pass options such as -nostdlib in order to cross compile the support libraries. The solution? Look at this article on LLVM's docs. Please note that this is for compiler-rt, but the process for libc++ should be somewhat similar (just different option names. Use the ccmake configuration tool in the build directory of libc++ to look at the available options for libc++). Note that when it says /path/to/clang for instance, this is the compiler that was built, not /bin/clang.
nexos wrote:Cross compiling LLVM is an absolute nightmare. The problem with what you're doing is that you're telling the build system to build libc++ with the host the same command line as the programs like clang. This won't work because we need to pass options such as -nostdlib in order to cross compile the support libraries. The solution? Look at this article on LLVM's docs. Please note that this is for compiler-rt, but the process for libc++ should be somewhat similar (just different option names. Use the ccmake configuration tool in the build directory of libc++ to look at the available options for libc++). Note that when it says /path/to/clang for instance, this is the compiler that was built, not /bin/clang.