When compiling and linking with g++ and clang++ there is an expectation that the resulting executable will be linked equal with respect to their linkage.
However in certain cases it appears that clang++ executables are linked to more libraries than g++ despite the same arguments passed in.
This can cause functional differences especially with respect to dynamically linked libraries that have automatic execution on load and unload.
Why does this happen?
It turns out gcc has a feature enabled by default in ubuntu --as-needed
which causes gcc to effectively ignore any library for which none of it's symbols are referenced in the chain of linked items
This can be disabled in gcc with --no-as-needed
flag. Or alternatively you can issue -Wl,--as-needed
as the first option to clang++ to behave the way gcc does.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With