views:

25

answers:

1

Let's say I have a source file, say helper.c, which gets compiled into an object library (helper.a). Now, this uses functionality from many system libraries, so currently when I want to link helper.a into an executable, I end up having to list all the dependencies:

gcc main.c helper.a -o my_app -lrt -lpthreads ...

What's the common approach to avoiding this tedium and maintenance issue? Is there some way of embedding information about the dependencies into the library so GCC can find them at link time? Or does one have to statically link the dependency libraries into helper.a?

A: 

Some compilers can generate a text file containing all the dependencies of the file being compiled. Check your compiler's documentation.

Include this text file into your makefile to resolve the dependencies.

Thomas Matthews