[llvm-dev] Failed to replace stdlibc++ with libc++, linker phase error

Tom Stellard via llvm-dev llvm-dev at lists.llvm.org
Fri Apr 12 18:38:39 PDT 2019


On 04/12/2019 06:31 PM, Tom Stellard via llvm-dev wrote:
> On 04/12/2019 04:28 PM, AiChi via llvm-dev wrote:
>> Hi,
>>
>> 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.

-Tom

>> 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.
> 
> -Tom
> 
>>
>> 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
>>
>>
>> Thanks for any ideas,
>> Aichi
>>
>>
>> _______________________________________________
>> LLVM Developers mailing list
>> llvm-dev at lists.llvm.org
>> https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev
>>
> 
> _______________________________________________
> LLVM Developers mailing list
> llvm-dev at lists.llvm.org
> https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev
> 



More information about the llvm-dev mailing list