0

Let's say that I have two static libraries : libA and libB and that libB uses libA.

For each library libX let's say that hX is libX's headers's directory and dX is libX's file's directory.

Now what happen when a user of libB wants to compile a source code C.c using libB ? Must he be aware that libB uses libA and so he must type :

gcc -IhB -IhA C.c -lA -LdA -lB -LdB

Or is there a way to make libB automatically 'says' to gcc to use libA so a user could type :

gcc -IhB -IhA C.c -LdA -lB -LdB

?

5
  • 1
    I added the ar tag because the question crops up frequently in connection with ar (static) libraries. The answer does depend on whether you've got libA.a or libA.so (or some other shared library suffix), and whether you've got libB.a or libB.so. If any one of the libraries is static (.a), the answer is "No". If they're all shared, the answer becomes "Maybe". Note that pkg-config is a system that's intended to help. Also, the AutoTools (autoconf and more particularly libtool) may be able to help. Jan 27, 2020 at 19:23
  • 1
    You should look at the Q&A in the ar tag — there aren't many of them, and a number of them are relevant. Jan 27, 2020 at 19:24
  • So, if libB uses 10 libs which themselves use 10 libs libB's users must know each of the 100 libs ?
    – Dadam42
    Jan 27, 2020 at 19:25
  • 1
    Unless there's overlap (so that it's only 90 distinct libraries), then yes. Which is where tools like pkg-config come in handy. Jan 27, 2020 at 19:26
  • Ok thank you for your help.
    – Dadam42
    Jan 27, 2020 at 19:28

1 Answer 1

1

Yes, all static libraries which are required must be listed on the command line. These are just special archive files that provide .o files. Just like you cannot omit required .o files, you cannot omit required archives.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.