[Configuration environment] Installation and use of the C/C++ third-party library management tool vcpkg under Windows

1. Introduction to vcpkg

  • vcpkg is an open source C++ package management tool developed by Microsoft, which can easily help you download, compile and install C++ third-party libraries on Windows, Linux and MacOS. It has the ability to automatically resolve dependencies and supports a variety of target architectures and platforms.
  • Provides more than 1500 pre-compiled binary packages of C++ libraries, and also provides a set of command line tools to help users install, uninstall, upgrade and manage versions of C++ libraries.

advantage:

  1. Automatically download the source code of the open source library and compile it easily
  2. Cache management and version management of source package, version can be upgraded
  3. Dependency check (such as compiling libcurl, it will automatically download zlib and openssl to compile)

Second, download vcpkg

Preconditions:

  • Git - Downloads  download the latest version according to the platform (fool installation)
  • Visual Studio  2015 or newer ( with English language pack )
    • Click Tools -> Get Tools and Features in the menu bar of the VS interface to check whether to download the English language pack
  • Windows 7 or newer

Step 1: git clone  vcpkg  repository

  • Right-click the mouse under the C drive path, click Git Bash Here to pop up the command window
  • Enter: git clone https://github.com/microsoft/vcpkg.git

Step 2: Generate vcpkg.exe

  • Execute bootstrap-vcpkg.bat  in the vcpkg directory to build vcpkg

Step 3: Configure the environment variables of vcpkg

  • Table of vcpkg commands
vcpkg search [pat]

Search for available packages to build

vcpkg install <pkg> install package
vcpkg remove <pkg> Uninstall the installation package
vcpkg update List packages that can be updated
vcpkg remove --outdated uninstall all obsolete packages
vcpkg upgrade rebuild all outdated packages
vcpkg hash <file> [alg] Hash the file by a specific algorithm, default is SHA512
vcpkg help topics Show list of help topics
vcpkg help <topic> Show help on a specific topic
vcpkg list list installed packages
vcpkg integrate install Make installed packages available user-wide, requires admin first-use privileges
vcpkg integrate remove Delete user-scoped integrations
vcpkg integrate project Generate a referenced NuGet package for a single VS project using
vcpkg integrate powershell

Enable PowerShell Tab Completion

vcpkg export <pkg>... [opt]... export a package
vcpkg edit <pkg>

Open a port for editing (using the environment program, defaults to "code")

vcpkg create <pkg> <url> [archivename] create a new port
vcpkg x-init-registry <path> Initialize registry in directory <path>
vcpkg format-manifest --all Format all vcpkg, json files, run this command before submitting to vcpkg
vcpkg owns <pat>

Search for files in the installation package

vcpkg depend-info <pkg>...

show a list of dependencies for a port

vcpkg env Create a clean shell environment for development or compilation
vcpkg version

show version info

vcpkg contact

Show Contact Information Send Feedback

@response_file Specify a response file to provide additional parameters
See the attached README for more help, including examples. Md and docs folder

Step 4: vcpkg installs third-party libraries

  • Install 32-bit (installed by default) 
    •  vcpkg install [package name]
  • Install 64 bit
    •  vcpkg install [package name]:x64-windows

  • Problems with installing third-party libraries
  • Solution: switch the cmd window to the vcpkg directory, and run the git pull command to get the latest vcpkg code

  • Successful installation of third-party libraries (libevent library)
  • You can view the installed libraries in the vcpkg/packages directory

Step 4: Integrate the downloaded library into the project

  • Command: vcpkg integrate install
  • After execution, VS can automatically access the library installed under [vcpkg-path]/installed, and we don't need to configure the library environment for the project.
  • After this, you can create a non-CMake project (or open an existing one). In your project, all installed libraries are ready to use  #include header files containing the libraries you need to use without additional configuration.

Guess you like

Origin blog.csdn.net/weixin_43729127/article/details/131056903