Vcpkg: dynamic or static? CRT and Library linking

Created on 9 Feb 2020  路  2Comments  路  Source: microsoft/vcpkg

I've been reading threads, issues, and posts for a while about the c-runtime and the library linking, but I'm still confused about how to set up these two parameters when using mixed triplet, as vcpkg provides separate settings for the two variables.

  set(VCPKG_CRT_LINKAGE static)
  set(VCPKG_LIBRARY_LINKAGE static)

(I'm using Visual Studio under Windows OS)
What I've understood so far (simplified):

  1. CRT Linkage is related to the Md/Mt settings, and related to how modern cpp implementation interprets the c99 code.
  2. The library linkage settings result either the all the libraries are linked statically (exe big, no dll), or dynamically (exe small, have dll, but potentially more linking issues if handled unproperly)
  3. Some library only support / prefer dynamic linking, such as Qt, TBB, etc.

It seems using pure x64-windows triplet where everything is dynamic works most of the time, but there're advantages for using static version at some circumstances. I've tried different combinations (enable either of the two settings or enable both) in my x64-windows-mixed environment and different projects sometimes fail for the compilation.

Here is my question which I still cannot summarise good enough from the posts I read and need to ask here:

  1. Are there specific advantages to use static libraries.
  2. What is the suggested way of setting CRT/Library-linkage combination? I would say I still don't quite understand the need for using either in static mode...

P.S. I used to set both to static and only use dynamic for some libraries like Qt, but that gives me some issue on one of my projects. Then I use static only for the "library linkage", other issues for compilation emerges from some of the libraries...
I already know that once I changed the triplets, I need to re-install the package I used from vcpkg.

It'll be super appreciated if someone can help me to understand the overall concepts and in-between connections.
Thank you.

question

Most helpful comment

This is really not vcpkg specific. CRT linking should generally be consistent between all parts of your program unless the library interfaces have been carefully designed to allow mixing.
Compiling some libraries into shared libs and some into static should work in principle, but there can always be library specific reasons, why a particular combination doesn't work.

All 2 comments

This is really not vcpkg specific. CRT linking should generally be consistent between all parts of your program unless the library interfaces have been carefully designed to allow mixing.
Compiling some libraries into shared libs and some into static should work in principle, but there can always be library specific reasons, why a particular combination doesn't work.

Please reopen if it still be a probem for you.

Was this page helpful?
0 / 5 - 0 ratings