linking static library

Hi all,

I'm kinda new to compiling on linux, but I'm learning. I've created a makefile to create a static library from the project. That library itself also depends on other static libraries, like pthread (or at least I think it is an static library, because I need to link it like -lpthread when using g++). But when I make a program that uses that library and I add it like -l mpi.a, it still needs -lpthread to link the program with. Is there a way to somehow have pthread included in mpi.a? I'm a bit used to VC++ where the static libraries already had the other static libraries included where they depended on itself.
Static libraries are simple archives of object files. There is no place to put dependency information in there.

Dynamic libraries can be made aware of their external dependencies. You should prefer dynamic libraries unless you have a compelling reason to use static ones.

As PanGalactic already said, a static library (extension: .a) is really only an archive (hence .a) of object files that doesn't have the ability to remember any depencdencies.

However, if your library "mpi" depends on the library "pthread", any program that you link with "mpi" will give a lot of undefined references. the reason is that you need to link your program with BOTH libraries, like in this over-simplified example:

g++ -lpthread -lmpi -omyprog myprogram.cpp
Topic archived. No new replies allowed.