1 Install Vcpkg
1-1 clone code
cd D:/vcpkg
git clone https://github.com/microsoft/vcpkg
1-2 Compile vcpkg
cd .\vcpkg\
.\bootstrap-vcpkg.bat
1-3 Add environment variables
Add the path to vcpkg.exe to the environment variable
1-4 Update vcpkg
Enter the vcpkg directory
git pull
./bootstrap-vcpkg.bat
2 Vcpkg use
Installation library
# x86 的 Windows 版本
vcpkg install spdlog
# 64 位 Windows 版本
vcpkg install spdlog:x64-windows
# 编译安装静态库
vcpkg install spdlog:x64-windows-static
Delete library
vcpkg remove spdlog:x64-windows
Update library
vcpkg upgrade spdlog:x64-windows --no-dry-run
Query installed open source libraries
vcpkg list
Query vcpkg included library
vcpkg search spdlog
Export the open source library (usually when using a third-party open source library in a project, it will be copied to the project folder for use)
vcpkg export spdlog:x64-windows --zip
3 Vckpg integrated into Visual Studio
3-1 Global integration
Installed third-party libraries can be used directly in any Visual Studio project
vcpkg integrate install
Remove global integration
vcpkg integrate remove
3-2 Integrate into the project
Use the nuget plug-in in Visual Studio to integrate vcpkg into the project
Open the console interface through the menu "Tools-NuGet Package Manager-Package Manager Console", and you can easily execute NuGet Package Manager commands in Visual Studio.
If there is no nuget plug-in, you can execute the command
vcpkg integrate project
Generate nuget configuration file
Here are some commonly used NuGet package manager console commands:
Install package: Execute the following command in the console to install the specified package:
Install-Package package name
Uninstall package: Execute the following command in the console to uninstall the specified package:
Uninstall-Package Package name
Update package: Execute the following command in the console Update the specified package:
Update-Package package name
Restore package: Execute the following command in the console to restore the dependencies of all installed packages:
Restore-Package
List installed packages: Execute the following command in the console to list all installed packages Installed package:
Get-Package
4 Vckpg integrated into CMake
vcpkg install spdlog
Add the following content to CMakeList.text
find_package(spdlog CONFIG REQUIRED)
target_link_libraries(main PRIVATE spdlog::spdlog)
# Or use the header-only version
find_package(spdlog CONFIG REQUIRED)
target_link_libraries(main PRIVATE spdlog::spdlog_header_only)