unixlinkerlibraries

UNIX: Linking an executeable to both a static library and dynamic library?


I admit this is a homework question that asks if this is possible. I believe the answer to it is yes, however I do not know the answer to the question 'why?'. To me, it seems like the answer is simply 'why not?'... can anyone provide some deeper insight to why this is true (or untrue, if I am wrong)? It seems like this question would only be asked if there was a tricky part to it, but from what I understand of compiling, there doesn't seem to be anything that would disallow linking to both.


Solution

  • Yes, of course you can link both a static library and a dynamic library. Linking to a static library is essentially the same as grabbing the required object files from the archive and including them in the linking process.

    If the static library and the dynamic library you're linking is for the same library, then the dynamic link is redundant. It's still allowed to be done, but it'd be pointless (and just introduces an unnecessary runtime dependency for your executable, at least on Unix).