G ++ linker does not recognize -Bstatic

My question is an extension of this question

I want to link to 2 libraries - fooand barprefers static for foo and dynamic for bar. If i use

g++ -static -lfoo -lbar

he is trying to find static archives for foo and bar. When I change the team to

g++ -Wl,-Bstatic -lfoo -Wl,-Bdynamic -lbar -Wl,--as-needed

according to the SO question above, this is the error I get:

ld: unknown option: -Bstatic

Update: I am using OSX if that matters

+5
source share
2 answers

Are we dealing with the GNU linker here? Can you show us the output of "ld -v"?

EDIT:, GNU ld, -Bstatic . , Apple ld ; . : Mac OS.

+5

, , OS X . -static ( OS X), , , -Wl, -Bstatic Apple clang.

Mac, :

g++ myapp.cpp libfoo.a libbar.a

( ). myapp, foo bar, .

0

All Articles