开发者

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

I admit this is a homework q开发者_C百科uestion 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.


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).


In general, there should be no reason why you can't link to both static and dynamic libraries, especially if they do not conflict (for instance, provide the same symbols). The mechanism to do so will differ depending on your complier, but many Free Software projects actually do this -- they build a so-called "convenience library" statically that then gets linked into a dynamically linked executable.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜