tags:

views:

51

answers:

1

I've known that I should use -l option for liking objects using GCC. that is gcc -o test test.c -L./ -lmy

But I found that "gcc -o test2 test.c libmy.so" is working, too.

When I use readelf for those two executable I can't find any difference. Then why people use -l option for linking objects? Does it have any advantage?

+4  A: 

Because you may have either a static or a shared version of the library in your library directory, e. g. libmy.a and libmy.so, or both of them. This is more relevant to system libraries: if you link to libraries in your local build tree, you know which version you build, static or shared, but you may not know other systems' configuration and libraries mix.

In addition to that, some platforms may have different suffixes. So it's better to specify it in a canonical way.

Alex B