To use a third-party library, you first need to install it. In no
vcpkgIn the past, the installation of third-party libraries needed to be compiled and linked locally. If we are novices, we will inevitably encounter problems that are difficult to solve in one way or another. But yes
vcpkgIt will be different in the future,
vcpkgWill automatically complete all this for us.
withAdministrator privilegesRun PowerShell and execute the commands of clone project, batch file and integration installation:
PS C:\Users\panjie\github> git clone https://github.com/microsoft/vcpkg --depth=1 PS C:\Users\panjie\github> cd .\vcpkg\ PS C:\Users\panjie\github\vcpkg> .\bootstrap-vcpkg.bat
Wait a moment, and the prompt of successful installation will be displayed.
vc++ package managerShort for, i.e
VC + + package manager, it functions like other package managers. But it may be that C + + appeared earlier, so its package manager didn’t do it
npmSuch a manager is so excellent.
Install third party packages
vcpkgInstalling third-party packages is very simple and requires only execution
Name of vcpkg install packageJust. If we don’t know the specific name of the package, we can also use
Name of vcpkg search packageTo search, for example, we want to achieve
websocketFunction, you can perform:
.\vcpkg.exe search websocket。
PS C:\github\vcpkg> .\vcpkg.exe search websocket beast 0 HTTP/1 and WebSocket, header-only using Boost.Asio and C++11 brynet 1.11.0 A C++ header only cross platform high performance tcp network library, and sup... bsio 1.0.0 networking library, ans support HTTP/WebSocket, based on asio. cpprestsdk[websockets] Websockets support ixwebsocket 11.2.6 Lightweight WebSocket Client and Server + HTTP Client and Server ... uwebsockets 18.104.22.168 Simple, secure & standards compliant web I/O for the most demanding of applica... websocketpp 0.8.2#1 Library that implements RFC6455 The WebSocket Protocol
Or you can open ithttps://vcpkg.io/en/packages.htmlSearch.
This page gives the package name, version number, main function description and compatibility. click
View DetailsInstallation commands are also given.
For example, we install it in Windows system at this time
View DetailsFollow the prompts given:
.\vcpkg install websocketpp
I need it hereParticular attentionThe key points are:
vcpkgThe default installed package is
x86-windows, if our current computer is
64Bit, it needs to be added after the corresponding package name
：x64-windowssuffix. For example, our correct command should be:
.\vcpkg install websocketpp:x64-windows
If you just want to learn, you can try to use it
vcpkg install libzip:x64-windowsTo install a smaller package:
libzip。 If your operating system is 32-bit, it needs to be removed
Most of the errors in the installation process are caused by the network. The speed of installation depends on the CPU compilation speed of the computer. All we have to do is wait patiently. If you stay in which interface during installation, you need to view it
vcpkgWhether the data is being downloaded (check the network condition) or compiled (check the CPU usage). If both are not, we need to press enter to help it.
vcpkg installDepend on
cmake, if not installed on the current computer
vcpkgWill be automatically downloaded and installed. What we need to ensure is that the current computer network is unblocked.
After successful installation
vcpkgYou will be prompted how to
cmakeConfigure the current package in the project:
Elapsed time for package websocketpp::x64-windows: 10.13 s Total elapsed time: 32.09 min The package websocketpp:x64-windows provides CMake targets: find_package(websocketpp CONFIG REQUIRED) target_link_libraries(main PRIVATE websocketpp::websocketpp)
If we use
cmakeProject, you only need to copy the above two commands and add them to
The successful installation of the third-party package is not the ultimate goal. Our ultimate goal is to load the third-party package into our project.
There are two types of projects: the first is an application developed using Visio studio, which is based on
MSBuildConstruction; The second type is based on other tools
cmakeTo use third-party packages in, you need to let
cmakeThe third-party package can be found successfully.
vcpkgA method for
cmakeAdd parameters to achieve this function.
vcpkg integrate installAfter, you will get the following prompt information:
PS C:\Users\panjie\github\vcpkg> .\vcpkg.exe integrate install ... //If you are under cmkae project, you can add corresponding parameters CMake projects should use: "-DCMAKE_TOOLCHAIN_FILE=C:/Users/panjie/github/vcpkg/scripts/buildsystems/vcpkg.cmake"
For example, in existence
CMakeLists.txtExecute on Path:
At the same time, you can also add compilation parameters to the IDE, so that the IDE will automatically add the above parameters when compiling. Take clion as an example:
To use in Visio studio
vcpkgTo manage third-party packages, Visio studio needs to be able to successfully find third-party packages. because
vcpkgIt’s also Microsoft’s own thing, so it’s very convenient to use. As long as the version of Visio studio we use is greater than 2015, we can use it
vcpkg.exe integrate installTo combine vs with vcpkg.
PS C:\Users\panjie\github\vcpkg> .\vcpkg.exe integrate install Applied user-wide integration for this vcpkg root. //All msbuild C + + projects can use #include to use any installed third-party libraries. The implication is that we can directly use #include to reference third-party libraries in Visio studio in the future All MSBuild C++ projects can now #include any installed libraries. Linking will be handled automatically. Installing new libraries will make them instantly available. ...
It should be noted that if we are using Visio studio, we need to ensure that the English language pack is installed in the current vs. Otherwise, you will get the following warning message:
Warning: The following VS instances are excluded because the English language pack is unavailable. C:\Program Files (x86)\Microsoft Visual Studio17\Community Please install the English language pack. No suitable Visual Studio instances were found
If you need to install the English language pack for vs, and then execute it again:
vcpkg integrate install
After installing the package, you can use the following commands to use the third-party package in the project:
#Include < package name / header file name. H > or #Include < package name / header file name. HPP >
Note that the above format is
#Include < package name / header file name. Suffix >。 If the IDE prompt you use does not find the relevant header file, you may need to restart.
Normally, the above operations are all in accordance with the official documents, and there should be no problem. But there is but, sometimes it just can’t.
vcpkgAfter installation, the relevant header files are not found automatically by using Visio studio. Still prompt: can not open source file “XXX. H”.
Some people say it’s time to re execute
vcpkg.exe integrate installIs this integrated command solved? The answer is no, because
vcpkg.exe integrate installThe function of the command is to add a point to the function of adding third-party dependencies for Visio studio
vcpkgLinks, that is, as long as
vcpkgWhen a new package is installed, Visio studio will be updated immediately.
visio studioThere was no immediate update, mostly because we did not install it successfully.
The standard for judging whether a package is successfully installed is also very simple. Let’s open it
installedSubfolder. If the current system is 64 bit, click
x64-windowssee; If it is 32-bit, click
If there is a corresponding generated folder named by a third party, the description
vcpkgIf the installation is successful, the problem should be in the integration phase of Visio studio.
If there is no corresponding folder, there is a problem with the installation. This problem is mostly due to forgetting to add it during installation
:x64-windowsCaused by suffix.
If we are not interested in using a vs version less than 2015, we may need toWith nuget