Using Specified Lib Version in Vcpkg

Vcpkg is a Microsoft C and C ++ library management solution on the Windows platform. Of course, Vcpkg can also run on Linux and Mac platforms. However, these two platforms already have their own default library system, so I think most developers are unlikely to use vcpkg as their own library management.

On Windows, there is always a lack of a unified Library Manager. We always use case by case way to solve libraries installation. In addition, Windows does not have a unified compilation environment. It is fundamentally different from the way of unix, you can’t use a makefile to complete all the work. In short, everything works unusual. Vcpkg is such an important tool to solve this problem.

Fatal disadvantage: no version management

Let me take an example of the problem I have recently encountered: I think that everyone who develops OpenGL or scientific computing will use the two function libraries GLM and GLFW3. In Vcpkg you simply use:

.\vcpkg install glm glfw3
.\vcpkg integrate install

In this way, you can easily use these two libraries directly in your Visual Studio project, and even Header, Includes, Libs can be used without any settings. Visual Studio will be smart enough to help you prepare the necessary DLLs for you based on dependencies. Everything seems so wonderful but one of its huge hidden problems and shortcomings is that, assuming that you have different projects that need to use different versions of the libraries. Sorry!!! Vcpkg does not have the function of multiple version management. At this time you cannot use “One” Vcpkg to meet all your needs.

Vcpkg a solution based on GIT version control

Any synchronization and update of Vcpkg will bring a lot of conflicts and problems. Maintaining a specific set of Vcpkg is important to ensure the normal operation of the project.

Solution 1: Use multiple Vcpkg

Because Vcpkg is based on GIT. Therefore, we can understand which Vcpkg is best for us by observing GIT Log. Take OpenSSL as an example:

Vcpkg checkout Tag

My project needs to use OpenSSL 1.0.2s version. But the head version of Vcpkg is OpenSSL 1.1.1, so I cannot use the head version on the master. The easiest way is to use a specific Tag directly. Because the version of Tag is mostly stable. As a result, I have an proprietary Vcpkg in my project.

+- vcpkg

Install OpenSSL:

.\vcpkg integrate project

Open Package Manager Console:
Visual Studio -> Menu -> Other Windows -> Package Manager Console

Package Manager Console

Install the nupkg installation path generated by Vcpkg :

Install-Package vcpkg.C.vcpkg -Source "path\vcpkg\scripts\buildsystems"

After installation, your Visual Studio can automatically reference and compile these libraries. Very convenient. And no manual setting is required.

Please note that you can only use one nupkg generated by Vcpkg at the same time. Only one Vcpkg nupkg is valid. Of course, your installed nupkg owns the higher priority, you don’t have to worry about other Vcpkg. In other words, other Vcpkg integrate install will not affect your project. This point is very important.

Solution 2: Use independent nupkg installation package

Fortunately, we can package the Vcpkg installed in Solution 1 into an independent installation package. In this way, we only need to refer to this installation package in the project to avoid re-downloading and compiling the entire Vcpkg.

Pack the nupkg installation package:

.\vcpkg export boost boost:x64-windows zlib --nuget

In this way, we have a name: vcpkg-export-20200417–005338.nupkg. And it only requires about 250MB of space. Next, we only need to distribute this installation package to all projects that need these libraries, and we can easily solve the problem of installing the libraries.

For example, we may check out a new project and then we just install this standalone nupkg file.

Install-Package vcpkg-export-20200417-005338 -Source "path of nupkg"

Note that installing packages in this way also cannot support multiple Vcpkg nupkg. It will also be affected by root Vcpkg integrate so that please remember to remove the integrated installation of root Vcpkg before compiling. Use root .\vcpkg integrate remove.




Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store