If both A and B are static, then you have to link both, in order of A then B (-la -lb
). See this reply for an explanation of the order.
A statically linked program includes the libraries its linked against inside of the executable.
Imagine your program calls foo()
inside of A, and somewhere inside of A, bar()
gets called. So if A becomes part of your program, you then have an undefined call to bar()
in your program, which is why you need to link against B as well.
The exception to this is when a special Visual Studio pragma is used (#pragma comment(lib, libname)
) as mentioned by @1201ProgramAlarm.