Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support static linking with /MT /MTd #36

Closed
aardappel opened this issue Sep 20, 2016 · 7 comments
Closed

Support static linking with /MT /MTd #36

aardappel opened this issue Sep 20, 2016 · 7 comments
Assignees
Labels
category:vcpkg-feature The issue is a new capability of the tool that doesn’t already exist and we haven’t committed

Comments

@aardappel
Copy link

Maybe it is already possible, but the docs so far appear to imply code gets compiled into DLLs.

Please also support compiling all code into a .lib with /MT /MTd runtime libraries for those of use who prefer their executables to be self-contained (or document how it is done).

@ras0219-msft
Copy link
Contributor

DLLs are the hardest, so we've focused on them first, but static linking is definitely a needed feature!

Our current plan (open for discussion) is to have /MT be configured in the triplets files. So, you would add a single line to triplets\<triplet>.cmake like set(VCPKG_VS_CRT_LINKAGE STATIC). This would likely need to be combined with a separate set of triplets (like x86-winstatic).

In Visual Studio, this triplet would automatically get picked whenever /MT is selected.

@Orvid
Copy link

Orvid commented Sep 20, 2016

If we're discussing static linking, it might be worthwhile asking how to handle LTCG (primarily for the purposes of PGO), as not all libraries can be compiled as static libraries. (there are probably a few out there that don't play nice with LTCG, but those should be significantly rarer)

Are there any plans to also support individual libraries as statically-linked but built against the dynamic runtime?

@alexkaratarakis alexkaratarakis self-assigned this Sep 28, 2016
@alexkaratarakis
Copy link
Contributor

I have created a new branch: staticlibs.

In this branch we introduce an initial approach to supporting static libs.
Static libs are treated as a separate triplet. For example, in addition to x86-windows there is now x86-windows-static.

The triplet definitions in triplets\ specify some variables that can be used by the portfiles to configure the build appropriately. Currently, we have modified zlib only to take them into account and build either dlls or static libs.

To install zlib dlls or static libs you need the following commands, respectively:

vcpkg install zlib:x86-windows
vcpkg install zlib:x86-windows-static

We welcome feedback on the approach we have taken. In particular, one of the points that was raised is the name of the triplets. Some alternatives are:

x86-win (for dlls, instead of x86-windows)
x86-winstatic
x86-win-static

@ras0219-msft ras0219-msft added category:vcpkg-feature The issue is a new capability of the tool that doesn’t already exist and we haven’t committed discussion needed labels Sep 30, 2016
@adam4813
Copy link
Contributor

Is this issue resolved via #97 and therefore can be closed or is there still something missing needing to be addressed @aardappel

@aardappel
Copy link
Author

@adam4813 : thanks, this is very helpful.

One issue that worries me is that now each package needs to explicitly support static linking in its portfile, and if portfile authors are generally omitting this, it will be some pain for those using static linking getting that fixed.

Since most open source libraries have no particular requirements on what their code gets compiled into, a default solution that automagically is able to link statically would have been even better.

But this is already entirely workable, so feel free to close the issue.

@ras0219-msft
Copy link
Contributor

To fill in a few more details about the support we've added with #97: these settings are controlled by the variables VCPKG_CRT_LINKAGE and VCPKG_LIBRARY_LINKAGE inside the triplet file [1]. These will then be used by vcpkg_configure_cmake to automatically set the appropriate compiler options and BUILD_SHARED_LIBS, so cmake-based ports will generally get support for free :) (@aardappel).

Are there any plans to also support individual libraries as statically-linked but built against the dynamic runtime?

@Orvid Yes, this is supported! We don't currently ship with a triplet that has the appropriate settings, but you can create your own triplet or modify the existing ones.

Finally, due to unfortunate interactions with the core of C++'s MSBuild, it is exceedingly difficult to reliably switch triplets based on the project's CRT linkage so we have removed that particular feature. <arch>-windows will always be selected when targetting Windows desktop and if you'd like to use an alternative triplet you will need to override the automatic detection.

  • MSBuild uses the property VcpkgTriplet which can be overridden with /p:VcpkgTriplet=<triplet> on the command line
  • CMake uses the macro VCPKG_TARGET_TRIPLET which can be overridden with -DVCPKG_TARGET_TRIPLET=<triplet> on the configure line
  • Other buildsystems are already encoding the triplet in their include dir and link dir, so just change those :)

[1] https://github.com/Microsoft/vcpkg/blob/master/triplets/x86-windows.cmake#L2

@aardappel
Copy link
Author

Thanks, that's even better :)

bartholmberg pushed a commit to bartholmberg/vcpkg that referenced this issue Feb 12, 2021
strega-nil pushed a commit to strega-nil/vcpkg that referenced this issue May 5, 2021
* Inherit gitattributes from the vcpkg repository when archiving tree

Ensures that file endings are consistent between the ports and the versioned port under `versioning`.

Fixes microsoft#16615 (comment). Before this fix, a patch with LF endings could end up with CRLF endings on Windows causing corrupt patch issues.

* Explicitly set core.autocrlf as false

Co-authored-by: Robert Schumacher <roschuma@microsoft.com>

* fix formatting

* -c has to be before archive command

Co-authored-by: Robert Schumacher <roschuma@microsoft.com>
strega-nil added a commit to strega-nil/vcpkg that referenced this issue May 5, 2021
The following PRs are included:

* hopefully fix crash in constraints (microsoft#60)
* [vcpkg] allow --version to check the version (microsoft#50)
* Remove baseline warning (microsoft#27)
* [git] always pass autocrlf=false (microsoft#58)
* ignore QtCreator CMake project files (microsoft#54)
* ignore .DS_store files (microsoft#53)
* [vcpkg] x-add-version now also checks if the manifest file is properly formatted (microsoft#43)
* hopefully fix ci issue microsoft#16773 (microsoft#34)
* Add docs to set VCPKG_ROOT to run tests (microsoft#45)
* [vcpkg] x-add-version improve speed by calling get_builtin_baseline only once (microsoft#44)
* add clang-format version to format-cxxcode (microsoft#41)
* [vcpkg] Introduce experimental workaround X_VCPKG_NUGET_ID_PREFIX (microsoft#40)
* [supports] Add `native` identifier expression and x-check-support command (microsoft#29)
* [metrics] Split reporting of installs into name:triplet (microsoft#39)
* [vcpkg] Improve error when accessing missing feature (microsoft#38)
* [vcpkg] Allow shallow git registries (microsoft#37)
* Disable git autocrlf when archiving tree (microsoft#36)
* Use only named packages from extra registries (microsoft#35)
* [registries] add metrics (microsoft#30)
* Add vcpkg policy cmake helper port support (microsoft#17)
* [osx] add support for rosetta (microsoft#23)
* don't build tls12-download unless it's needed (microsoft#33)
* Add new telemetry points for versioning (microsoft#21)
* add cmake_minimum_required to vcpkg_tags (microsoft#25)
* [x-add-versions] Perform atomic replacement of versioning files (microsoft#28)
* [tools] support gsutil (microsoft#19)
* add CUDA 11.1 and 11.2 to KEEP_ENV_VARS defaults (microsoft#26)
* Add finite timeout on CURL metrics endpoint. (microsoft#22)
* fix UB in make_error_code(utf8_errc) (microsoft#18)
JoergAtGithub pushed a commit to JoergAtGithub/vcpkg that referenced this issue Jul 2, 2022
[qtkeychain] remove from overlay and adjust port name
dempo93 pushed a commit to dempo93/vcpkg that referenced this issue Aug 23, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
category:vcpkg-feature The issue is a new capability of the tool that doesn’t already exist and we haven’t committed
Projects
None yet
Development

No branches or pull requests

5 participants