microsoft / vcpkg

C++ Library Manager for Windows, Linux, and MacOS
MIT License
22.9k stars 6.32k forks source link

If a pkg has both static and dynamic libs installed, which one will be used?How do I ... #17939

Closed playgithub closed 3 years ago

playgithub commented 3 years ago

When using the lib, only header files are included, how does vcpkg know to use the static lib or the dynamic lib?

PhoebeHui commented 3 years ago

@playgithub, for dynamic lib, it will deduce a triplet for your project. if you use it with cmake, you can pass the triplet with 'VCPKG_TARGET_TRIPLET'. For static lib, it depends on how you use the pkg: With cmake: You can set VCPKG_TARGET_TRIPLET on the configure line. With msbuild: you can specify the MSBuild property VcpkgTriplet in your .vcxproj.

See https://github.com/microsoft/vcpkg/blob/master/docs/users/integration.md#triplet-selection for details.

playgithub commented 3 years ago

@playgithub, for dynamic lib, it will deduce a triplet for your project. if you use it with cmake, you can pass the triplet with 'VCPKG_TARGET_TRIPLET'. For static lib, it depends on how you use the pkg: With cmake: You can set VCPKG_TARGET_TRIPLET on the configure line. With msbuild: you can specify the MSBuild property VcpkgTriplet in your .vcxproj.

See https://github.com/microsoft/vcpkg/blob/master/docs/users/integration.md#triplet-selection for details.

As far as I know, triplets are used for building the libs. My question is, if a lib got both shared and static versions installed, how to determine which one to use?

dg0yt commented 3 years ago

My question is, if a lib got both shared and static versions installed, how to determine which one to use?

In the context of vcpkg, if a lib from a vcpkg port has both shared and static versions installed, it is a bug in that port: The linkage is defined by the triplet, either "dynamic" or "static". (Triplet files may even define per-port exceptions.)

dg0yt commented 3 years ago

Guideline: https://vcpkg.io/en/docs/maintainers/maintainer-guide.html#choose-either-static-or-shared-binaries

playgithub commented 3 years ago

In the context of vcpkg, if a lib from a vcpkg port has both shared and static versions installed, it is a bug in that port: The linkage is defined by the triplet, either "dynamic" or "static". (Triplet files may even define per-port exceptions.)

Does it mean I can't use dynamic libs and static libs in vcpkg together? This might be inconvenient in some cases, e.g. I prefer dynamic link, but some libs (e.g. wxcharts) doesn't support dynamic link on Windows natively.

dg0yt commented 3 years ago

Does it mean I can't use dynamic libs and static libs in vcpkg together?

Dynamic and static libs can be used together if necessary: "Within a triplet, libraries are generally built with the same configuration, but it is not a requirement." (https://vcpkg.io/en/docs/users/triplets.html)

If a lib can't be build in one way, then linkage can be overwritten in the lib's portfile. The portfile may issue a hint when building the port

If you want to locally override the default linkage for a particular port, you would put the override into a custom (overlay) triplet file.

playgithub commented 3 years ago

Dynamic and static libs can be used together if necessary: "Within a triplet, libraries are generally built with the same configuration, but it is not a requirement." (https://vcpkg.io/en/docs/users/triplets.html)

If a lib can't be build in one way, then linkage can be overwritten in the lib's portfile. The portfile may issue a hint when building the port

If you want to locally override the default linkage for a particular port, you would put the override into a custom (overlay) triplet file.

Understand, I have to learn the details. Thanks