Vcpkg: How do I link statically against Qt 5.15.1 using CMake?

Created on 27 Oct 2020  路  10Comments  路  Source: microsoft/vcpkg

I really have scoured the web but am unable to find how to do this.

Not sure if it is related to vcpkg but I really have nowhere else to look.

I see that simply doing vcpkg install qt5 gave me a bunch of DLLs and .lib files, so they have been downloaded, but how can I specify CMake to link against the static libraries and not the DLLs?

Many thanks

question

All 10 comments

have you tried vcpkg.exe install qt5-base:x64-windows-static ?
I have the feeling this issue is not related to qt but how to generally use a triplet with static library linkage. (or you even want to use a custom triplet in your case)

My general advice here is to study the documentation of vcpkg ;)

Hi @STgithub64
Thanks for posting this issue.

Please refer to this doc https://devblogs.microsoft.com/cppblog/vcpkg-updates-static-linking-is-now-available/ to get how to use a static library in vcpkg.

@Neumann-A
Thanks for your help and guidelines.

Thank you very much for the help.

I was just slightly confused because static libraries were indeed built for Qt, even though I didn't specify that they should be downloaded statically, so I thought it was a specific option I had to indicate.

I will re-download Qt specifically as a static library and follow that tutorial and let you know if I have any problems.

Regards

Hi @STgithub64

Any updates about this issue?

Thanks for getting back to me @NancyLi1013

I tried building the static version of Qt with vcpkg but it failed. I'm reinstalling vcpkg fresh and retrying, but I don't think it will help.

Will let you know

@STgithub64 There are plenty of online cmake tutorials available you could have a look at.

The build succeeded (except for qt-declarative which I will post another issue about) but CMake is still building a dynamically-linked executable. I confirmed this by moving the executable to another PC, in which it didn't work and complained that it could not find Qt5Cored.dll.

Do I need to have any additionally settings to indicate I want static Qt linking in CMake? The internet wasn't too helpful on this.

Thanks.

@NancyLi1013

Do I need to have any additionally settings to indicate I want static Qt linking in CMake? The internet wasn't too helpful on this.

no. You indicate which triplet you want to use via setting -DVCPKG_TARGET_TRIPLET=x64-windows-static in your cmake build on first configure.

in which it didn't work and complained that it could not find Qt5Cored.dll.

which just means you did not link against Qt as a static library which probably means your VCPKG_TARGET_TRIPLET is incorrect or just not set. The default is x64-windows. Please read the documentation about integration (https://github.com/microsoft/vcpkg/blob/master/docs/users/integration.md) and triplets (https://github.com/microsoft/vcpkg/blob/master/docs/users/triplets.md)

This issue was closed, then reopened, then closed again and now opened again!
If cmake works as expected, then the issue is with vcpkg.

@STgithub64

Could you please help check if you have set the triplet correctly?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

tzbo picture tzbo  路  3Comments

pkeir picture pkeir  路  3Comments

pakdel picture pakdel  路  3Comments

jasjuang picture jasjuang  路  3Comments

oahzuw picture oahzuw  路  3Comments