Vcpkg: How to use static libs?

Created on 22 Jan 2017  路  14Comments  路  Source: microsoft/vcpkg

I've installed libmysql:x86-windows-static but I'm getting fatal error C1083: Cannot open include file: 'mysql/mysql.h': No such file or directory
How do I use a static lib?
I've tried both /MD and /MT for the project.

documentation

Most helpful comment

Shouldn't that be included in the vcpkg docs?

All 14 comments

Shouldn't that be included in the vcpkg docs?

You can also modify which triplet is integrated globally for given project settings by editing scripts/buildsystems/msbuild/vcpkg.targets

Would it make sense to default to static libs if the static CRT is selected?

The latest docs report nothing if searched through for static or linking.

Please, could the blog be even copied verbatim to docs?

Hello, even this has been an issue 2 years ago, i have the problem that static builds:
.\vcpkg.exe install zlib:x64-windows-static

cause a compiler error in VS 2017, because the headers are expected in
x64-windows
and not in
x64-windows-static. (e.g. #include )

So i checked out to set the tripplet by default to static in file vcpkg.targets
<VcpkgTriplet Condition="'$(VcpkgTriplet)' == ''">x64-windows-static</VcpkgTriplet>

and using command
.\vcpkg.exe install zlib:x64-windows
In the installed directory i get the libs below x64-windows. That should remove compiler errors,
but obviously, the libs are not static. The static x64 zlib has 419kb.
With the new default setting
<VcpkgTriplet Condition="'$(VcpkgTriplet)' == ''">x64-windows-static</VcpkgTriplet>
and
.\vcpkg.exe install zlib:x64-windows
The x64 zlib has 16kb.

It is a great tool and when it works, it saves much time and makes the whole solution more
transparent. Thank you for this!

Just..
What do you need to do, in order to get static 32- and 64 bit builds without the need for any further hacks and without compiling and linking errors ?

Thank you

@trade-commander1 this helps.

Hello,
thanks, make sense to change it in the project file. But this means i need to touch each project ?

@trade-commander1 Yes, but going forward, creating a project-template, with this mod in, solves your problem for the future.

You are right. Thank you for this.

No worries, you can, once you're at it, tune the project-template exactly to your liking, and overall gain a serious boost in productivity. I have a separate project for this, and house it on github [I'm not promoting for you to use this, it's specific to my system and the way I work, it's more about to show you how you could go about it].

I swtiched my solutions to use the vcpkg libs and could compile and link.
It is really great liniearization of my work and great contribution to c++ development. Thank you.

Hello, i failed to build tensorflow. The log reports:
ERROR: C:/projekte/dev_apps/vcpkg/buildtrees/.bzl/_bazel_general/yvqyet6t/external/snappy/BUILD.bazel:7:1: C++ compilation of rule '@snappy//:snappy' failed (Exit 2): cl.exe failed: error executing command

What does it mean ?

@trade-commander1 You'll have to open a new issue for that, don't forget to attach/copy the log files (as indicated in the error message). Maybe a bootstrap fixes it.

Was this page helpful?
0 / 5 - 0 ratings