I am creating an executable with this:
gcc elliptical.o -Llibs -lhfcal -o elliptical
In my libs sub folder there are:
libhfcal.a libhfcal.so
files. My purpose is to use dynamic library but still i didnt understand how it choose .so
file when i didnt explicitly refer it. I know it try to use .so
because when running executable i got
./elliptical: error while loading shared libraries: libhfcal.so: cannot open shared object file: No such file or directory
Using static library to create executable command as same as dynamics one. I know i need to use LD_LIBRARY_PATH
but my question is why compiler picked up dynamics library?
CodePudding user response:
From the gcc manual (emphasis mine):
-l library
Search the library named library when linking. (The second alternative with the library as a separate argument is only for POSIX compliance and is not recommended.)
The -l option is passed directly to the linker by GCC. Refer to your linker documentation for exact details. The general description below applies to the GNU linker.
The linker searches a standard list of directories for the library. The directories searched include several standard system directories plus any that you specify with -L.
Static libraries are archives of object files, and have file names like liblibrary.a. Some targets also support shared libraries, which typically have names like liblibrary.so. If both static and shared libraries are found, the linker gives preference to linking with the shared library unless the -static option is used.