0

I'm new to the world of building. I've always let my IDE take care of it for me, but now I'm working with autotools and command line.

Could someone explain the difference between gcc's
-l LIBNAME - Search for library LIBNAME
and -L DIRECTORY - Add DIRECTORY to library search path

Can the same linking be accomplished with either and it's just a style preference which gets used? Or is there actually something seriously different happening?

Thanks,

Andrew

JasCav
  • 34,458
  • 20
  • 113
  • 170
ajwood
  • 18,227
  • 15
  • 61
  • 104

2 Answers2

2

Usually you use both:

  • -l libname specifies the libraries you want to link, think single files.
  • -L specifies paths where the linker should look for them (in addition to the standard ones), think directories
Steffen
  • 2,888
  • 19
  • 19
  • So if I've got my own library /home/andrew/mylibs/libme.so, I have to use -L/home/andrew/mylibs/ -lme ? – ajwood Dec 21 '10 at 15:30
  • If I have both /home/andrew/mylibs/libme.so and /home/andrew/mylibs/libme.a, it seems to default to the .a. Is there a way to override and take the .so? – ajwood Dec 21 '10 at 16:19
0

The -L command adds a path to the list of locations the linker searches to find libraries.

The -l option means it searches for a library by the name you specify

Basically the -l option tells it to look for a library by that name and -L allows you to specify places to look.

More Information: http://linux.die.net/man/1/ld

Patrick
  • 178
  • 1
  • 6