Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Linking static libraries with clang independent of order

In GCC, I can use the linker flags -Wl,--start-group and -Wl,--end-group to resolve linking problems with libraries that have circular dependencies. I'd like to do the same with clang, but it seems like this feature was dropped in lld version 3.2. How do I do it?

like image 736
Mokosha Avatar asked Sep 23 '14 03:09

Mokosha


2 Answers

The release notes of LLVM 3.2 state 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 fully replaced by Clang.

By default clang seems to use the system linker. That is on Linux for example it uses the 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 with GCC.

like image 114
user1225999 Avatar answered Sep 28 '22 00:09

user1225999


I'm not a fan of circular dependencies :) but here some say they handle this cases by linking some libraries twice. I haven't tried it but this might increase your code's footprint.

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

I don't know if this works with clang but it might worth a shot.

Best solution would be removing the circular dependencies as it will generate you more problems in the future.

like image 45
VAndrei Avatar answered Sep 27 '22 22:09

VAndrei