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 stdlibc++ 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++?
I also noticed when it’s in linker phase, these flags were set in the ld command (-lc++ -lm -lgcc_s -lgcc -lc -lgcc_s -lgcc ), which we didn’t have them setup anywhere in our project, just out of curiosity, are they added automatically? Why are they needed?
A little bit more details:
Environment: CentOS Linux release 7.6.1810 (Core)
Clang version:
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 stdlibc++ 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:
1. 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++?
Can you post the full linker invocation with all the arguments?
What cmake arguments did you use when building libcxx and libcxxabi?
2. How can we resolve this error? (any ideas would be appreciated!)
Not sure exactly, I would try passing -DLIBCXX_CXX_ABI=libcxxabi to cmake
when configuring libcxx if you have not already.
3. Is there anything missing if we'd like to replace stdlibc++ with libc++?
4. I also noticed when it's in linker phase, these flags were set in the ld command (-lc++ -lm -lgcc_s -lgcc -lc -lgcc_s -lgcc ), which we didn't have them setup anywhere in our project, just out of curiosity, are they added automatically? Why are they needed?
When you are using clang++ or g++ as the linker driver, then it automatically
adds the flags for you.
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 stdlibc++ 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:
1. 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++?
Can you post the full linker invocation with all the arguments?
What cmake arguments did you use when building libcxx and libcxxabi?
2. How can we resolve this error? (any ideas would be appreciated!)
Not sure exactly, I would try passing -DLIBCXX_CXX_ABI=libcxxabi to cmake
when configuring libcxx if you have not already.
If you are looking for a quick fix though, you might want to also try adding
-lc++abi to your linker flags.
Following are the commands that I used to build clang/libcxx/libcxxabi:
clang: cmake -DLLVM_ENABLE_PROJECTS=``"clang;libcxx;libcxxabi"-G ``"Unix Makefiles"-DCMAKE_BUILD_TYPE=Release -DLLVM_LIBDIR_SUFFIX=64 ..``/llvm
And based on what I searched on google, libcxx and libcxxabi might have circular dependency (please see the post here: https://stackoverflow.com/questions/25840088/how-to-build-libcxx-and-libcxxabi-by-clang-on-centos-7), so after I built libcxx with clang, build libcxxabi based on libcxx, I rebuilt libcxx again with libcxxabi with the following command:
`
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 …
I’ve tried what you suggested in your previous email (add linker flag: -lc++abi), but unfortunately I got the same error while building my project. Am I missing anything?