Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Various representations of -Bstatic flags in ld

In manpage of ld (from binutils), there is this section about variations of -Bstatic flag:

-Bstatic
-dn
-non_shared
-static
Do not link against shared libraries. This is only meaningful on platforms for which shared libraries are supported. The different variants of this option are for compatibility with various systems. You may use this option multiple times on the command line: it affects library searching for -l options which follow it. This option also implies --unresolved-symbols=report-all. This option can be used with -shared. Doing so means that a shared library is being created but that all of the library's external references must be resolved by pulling in entries from static libraries.

My question is about the bolded sentence: exactly for which systems are these variants trying to be compatible? I have seen both -Bstatic and -static in various projects, but haven't seen anybody using the remaining two variants so far. For maximum compatibility (in terms of cross platform), which one is the best to use?

like image 375
Abel Cheung Avatar asked Jul 10 '15 12:07

Abel Cheung


1 Answers

The -Bstatic and -static options are currently used, and are not the same:

  • -static means: perform a completely static link (no shared libraries used at all).
  • -Bstatic means: for any -lfoo that follows, use only archive version of the library.

The other options: -dn (added in 1993) and -non_shared (added in 1994) are for compatibility with long-obsolete OSes.

like image 64
Employed Russian Avatar answered Sep 22 '22 20:09

Employed Russian