amosbird / ldb_toolchain_gen

MIT License
66 stars 21 forks source link

Clang13 in ldb_toolchain fails to compile simple test programs. #2

Closed BiteTheDDDDt closed 2 years ago

BiteTheDDDDt commented 2 years ago

I tried compiling some other projects(LLVM13/clang-tidy/include-what-you-use) with it and found that it always fails at the initial test phase. why is this?

 CMake Error at /home/disk2/pxl/dev/ldb_toolchain/share/cmake-3.22/Modules/CMakeTestCXXCompiler.cmake:62 (message):
  The C++ compiler

    "/home/disk2/pxl/dev/ldb_toolchain/bin/clang++-13"

  is not able to compile a simple test program.

  It fails with the following output:

    Change Dir: /home/disk2/pxl/dev/clang-tools-extra-13.0.0.src/clang-tidy/build/CMakeFiles/CMakeTmp

    Run Build Command(s):/usr/bin/gmake -f Makefile cmTC_a4c37/fast && /usr/bin/make64 MAC=64 -f Makefile cmTC_a4c37/fast
    /usr/bin/make64  -f CMakeFiles/cmTC_a4c37.dir/build.make CMakeFiles/cmTC_a4c37.dir/build
    make64[1]: Entering directory `/home/disk2/pxl/dev/clang-tools-extra-13.0.0.src/clang-tidy/build/CMakeFiles/CMakeTmp'
    Building CXX object CMakeFiles/cmTC_a4c37.dir/testCXXCompiler.cxx.o
    /home/disk2/pxl/dev/ldb_toolchain/bin/clang++-13    -MD -MT CMakeFiles/cmTC_a4c37.dir/testCXXCompiler.cxx.o -MF CMakeFiles/cmTC_a4c37.dir/testCXXCompiler.cxx.o.d -o CMakeFiles/cmTC_a4c37.dir/testCXXCompiler.cxx.o -c /home/disk2/pxl/dev/clang-tools-extra-13.0.0.src/clang-tidy/build/CMakeFiles/CMakeTmp/testCXXCompiler.cxx
    Linking CXX executable cmTC_a4c37
    /home/disk2/pxl/dev/ldb_toolchain/bin/cmake -E cmake_link_script CMakeFiles/cmTC_a4c37.dir/link.txt --verbose=1
    /home/disk2/pxl/dev/ldb_toolchain/bin/clang++-13 -rdynamic CMakeFiles/cmTC_a4c37.dir/testCXXCompiler.cxx.o -o cmTC_a4c37 
    /home/disk2/pxl/dev/ldb_toolchain/bin/../lib/gcc/x86_64-linux-gnu/11/libstdc++.so: undefined reference to `memcpy@GLIBC_2.14'
    /home/disk2/pxl/dev/ldb_toolchain/bin/../lib/gcc/x86_64-linux-gnu/11/libstdc++.so: undefined reference to `aligned_alloc@GLIBC_2.16'
    /home/disk2/pxl/dev/ldb_toolchain/bin/../lib/gcc/x86_64-linux-gnu/11/libstdc++.so: undefined reference to `clock_gettime@GLIBC_2.17'
    /home/disk2/pxl/dev/ldb_toolchain/bin/../lib/gcc/x86_64-linux-gnu/11/libstdc++.so: undefined reference to `__cxa_thread_atexit_impl@GLIBC_2.18'
    clang-13: error: linker command failed with exit code 1 (use -v to see invocation)
    make64[1]: *** [cmTC_a4c37] Error 1
    make64[1]: Leaving directory `/home/disk2/pxl/dev/clang-tools-extra-13.0.0.src/clang-tidy/build/CMakeFiles/CMakeTmp'
    make64: *** [cmTC_a4c37/fast] Error 2

  CMake will not be able to correctly generate this project.
Call Stack (most recent call first):
  CMakeLists.txt
amosbird commented 2 years ago

Yes, the limitation is already noted in README https://github.com/amosbird/ldb_toolchain_gen#how-to-avoid-glibc-incompatibility

However, it's indeed possible to improve. I'll investigate.

amosbird commented 2 years ago

Starting from v0.8 ldb_toolchain provides builtin glibc-compatibility. Please try if it suits your need. BTW, it doesn't mask standard c++ libraries, so you might need to link them (libstdc++ or libc++) statically.

amosbird commented 2 years ago

Now ldb_toolchain (>= v0.8.1) contains a bunch of useful libraries by default: libz, libtinfo, openssl etc. Ideally all these packages along with libstdc++ will be forced to link statically. However in Ubuntu distro most static libraries are compiled without -fPIC, which means we have to rebuild on our own. For now I'll leave it open as the toolchain is good enough.

More system headers are included. I've tested compiling Python3.6, LLVM-13 along with include-what-you-use on minimal centos 6. It works perfectly.