Can a C++ Static Library link to shared library?

后端 未结 3 1371
情深已故
情深已故 2021-02-12 14:44

Say I have a static C++ lib, static.lib and I want to call some functions from a C++ shared lib, say shared.lib. Is it possible?

Now assume that I have another shared li

3条回答
  •  没有蜡笔的小新
    2021-02-12 15:40

    Say I have a static C++ lib, static.lib and I want to call some functions from a C++ shared lib, say shared.lib. Is it possible?

    Yes for instance when you call windows functions from within your static lib they are normally from some dynamic library so there should be no difference.

    Now assume that I have another shared lib, say shared2.lib which links to static.lib but does not link to shared.lib. Does the linker automatically link shared2.lib to shared.lib in this case?

    Having dependencies like this one could cause problems later, I would suggest that you instead dynamically load the libraries using LoadLibrary(), that way you don't need to keep track of such dependencies while compiling/linking.

提交回复
热议问题