Gcc gcc library search order; paths plus static and shared

Reading in the gcc manual, I believe the following two statements are true:

  • The library search paths specified on the command line are looked up to the "standard" paths (which I assume they mean things in the LIBRARY_PATH environment variable)

  • Shared libraries will be bound to static libraries (in the absence of flags saying otherwise)

But which of these two dominates? For example, if I type

gcc myprog.cpp -o myprog -Lmypath -lmylibrary

and mypath has a static library libmylibrary.a, and at some place specified in LIBRARY_PATH, there is a shared library libmylibrary.so, which of these libraries will be used? I assume that the static library will be used (i.e. (1) dominates), but I see some funny compilation errors that make me question this assumption, so I wanted to make sure ...

+4
source share
1 answer

libmylibrary.a libmylibrary.a libmylibrary.so, . mypath , libmylibrary.a libmylibrary.so, -lmylibrary.

mypath libmylibrary.a, libmylibrary.so, .

, " gcc", "gcc-" - GNU, ld,

+3

All Articles