Linking static libraries to clang regardless of order

In GCC, I can use the -Wl,--start-group and -Wl,--end-group linker flags to solve problems with linking to circular dependency libraries. I would like to do the same with clang, but it looks like this function was removed in lld version 3.2 . How to do it?

+6
source share
3 answers

LLVM 3.2 release notes indicating that

llvm-ld and llvm-stub have been removed, llvm-ld functionality can be partially replaced by llvm-link | opt | {llc | as, llc -filetype = obj} | ld or completely replaced by the Clan.

By default, clang seems to use the system builder. For example, Linux uses GNU ld:

 $ clang --version clang version 3.2 (branches/release_32 170558) ... $ clang -Wl,--verbose GNU ld (GNU Binutils; devel:gcc / openSUSE_12.3) 2.24.0.20140403-196 ... 

This suggests that you can use -Wl, - start-group and -Wl, - end-group, as in GCC.

+4
source

I am not a fan of circular dependencies :), but here they say that they cope with these cases by linking libraries twice. I have not tried it, but it can increase your code footprint.

 $(CC) -o myApp -lfoo -lbar -lfoo 

I don't know if this works with clang, but it could be worth the shot.

The best solution would be to remove the circular dependencies, as this will create more problems for you in the future.

+3
source

I had a similar problem with a custom clang compiler using a QT C ++ project.

The problem turned out to be that QT used clang (c compiler), not clang ++ (C ++ compiler). By defining the compiler as clang ++ instead of clang in the QT project (setting QMAKE_CXX = clang ++), the project was successfully linked.

As I understand it, the same is true for gcc and g ++.

0
source

Source: https://habr.com/ru/post/975692/


All Articles