Two methods of linking an object using GCC?

I knew that I needed to use the -l option for objects using GCC. this is gcc -o test test.c -L./-lmy

But I found that "gcc -o test2 test.c libmy.so" also works.

When I use readelf for these two executables, I cannot find the difference. Then why do people use the -l option to bind objects? Does this have an advantage?

+3
source share
2 answers

Since you may have a static or general version of the library in your library directory, e. g. libmy.aand libmy.so, or both of them. This is more relevant for system libraries: if you link to libraries in the local assembly tree, you know which version you are creating, static or general, but you may not know how the configuration and libraries of other systems mix.

In addition to this, some platforms may have different suffixes . Therefore, it is better to indicate it in a canonical way.

+4
source

, -lname libname.a( libname.so ..) . -L. , , , .

0

Source: https://habr.com/ru/post/1749178/


All Articles