I'm currently working on one of my team's project to build LLVM full clang toolchain (Clang, libcxx, libcxxabi) on a CentOS machine.
Previously we compiled our codebase with llvm-toolset-7/clang++, which by default takes libstdc++ to compile and link. And now we'd like to switch to use LLVM clang with libc++. I have built libc++ and libc++abi from source (5.0.1 release) and set up related flags to compile our code base, but it turned out having some issue in the "linker" phase:
Flags set for complier:
-stdlib=libc++ -std=c++14
Flags set for linker:
-stdlib=libc++
Error:
/opt/rh/devtoolset-7/root/usr/lib/gcc/x86_64-redhat-linux/7/../../../../bin/ld: product.o: undefined reference to symbol '__cxa_free_exception@@CXXABI_1.3'
//lib64/libstdc++.so.6: error adding symbols: DSO missing from command line
clang-5.0: error: linker command failed with exit code 1 (use -v to see invocation)
My question is:
We plan to replace stdlibc++ with libc++, and we've set up compiler and linker to run with
-stdlib=libc++. Why is it complaining about libstdc++?How can we resolve this error? (any ideas would be appreciated!)
- Is there anything missing if we'd like to replace stdlibc++ with libc++?
A little bit more details:
Environment: CentOS Linux release 7.6.1810 (Core)
Clang version: clang version 5.0.1 (tags/RELEASE_501/final)
Target: x86_64-unknown-linux-gnu
Thread model: posix
cmake commands I used to build LLVM clang, libcxx and libcxxabi:
clang:
cmake -DLLVM_ENABLE_PROJECTS="clang;libcxx;libcxxabi" -G "Unix Makefiles" -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=/usr -DLLVM_LIBDIR_SUFFIX=64 ../llvm
libcxx:
cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=/usr -DLLVM_LIBDIR_SUFFIX=64 -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++ -DLIBCXX_CXX_ABI=libcxxabi -DLIBCXX_CXX_ABI_INCLUDE_PATHS=../../libcxxabi/include ..
libcxxabi:
cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=/usr -DLLVM_LIBDIR_SUFFIX=64 -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++ -DLIBCXXABI_LIBCXX_INCLUDES=../../libcxx/include ..