0

I'm fiddling around with GCC, trying to understand the various possibilities for linkage.

These are my questions:

  1. Let's say I have two files tools.c and tools.h, and I create an archive libtools.a (containing tools.o).

    Now I have some prog.c, a program which includes tools.h and uses some of its functions.

    are the following commands equivalent?

    gcc -Wall prog.c libtools.a -o prog

    gcc -Wall prog.c -ltools -o prog

  2. regarding the -l flag (man ld wasn't of much use unfortunately):

    a. What is the implicit pattern matching rule? -lX means "find the file named libX.a"?

    b. Does -l have any real importance in the linking process besides finding the library lazily (closely related to 1 I guess)?

    c. How do I link a library named lib.a or tools.paz?

Paz
  • 737
  • 7
  • 22

1 Answers1

0

Using -l you link dynamically, using the filename you link statically. I suggest you read the manpage of ld, which explains all this in detail.

ypnos
  • 50,202
  • 14
  • 95
  • 141
  • it appears under `-l`? about the static\dynamic, in http://stackoverflow.com/questions/3840218/how-to-specify-the-library-version-to-use-at-link-time the chosen answer says using -l and the filename are interchangeable, if I didn't misunderstand it. – Paz Jan 25 '14 at 12:46
  • See my answer here: http://stackoverflow.com/questions/4156055/gcc-static-linking-only-some-libraries/4156166#4156166 – ypnos Jan 25 '14 at 13:31