Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How gcc decide to use dynamics library when creating executable?

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

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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?

>Solution :

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.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading