Chuyển đến nội dung
Skillpedia
Lập trình chung40k · #7470

vcpkg

Skill này làm gì

vcpkg là công cụ giúp lập trình viên C++ quản lý các thư viện (gói) mà chương trình cần. Nó giúp cài đặt và sử dụng các thư viện này dễ dàng hơn trên các hệ điều hành và cấu hình khác nhau.

Khi nào nên dùng

  • ✓Khi bắt đầu một dự án C++ mới và cần thêm thư viện bên ngoài.
  • ✓Khi bạn muốn đảm bảo dự án dùng các phiên bản thư viện cụ thể.
  • ✓Khi biên dịch dự án cho các hệ thống (như Windows, Linux) hoặc kiến trúc (như 32-bit, 64-bit) khác nhau.

Liên kết skill

https://github.com/github/awesome-copilot/blob/main/skills/vcpkg/SKILL.md

Sao chép rồi dán vào AI của bạn (Claude, ChatGPT hoặc Cursor) và nhờ nó làm theo hướng dẫn.

Cách dùng

Cách dễ nhất: sao chép tin nhắn và dán vào AI của bạn. AI sẽ đọc skill và làm theo hướng dẫn.

Tin nhắn có sẵn để dán

Hãy dùng skill này để giúp tôi: https://github.com/github/awesome-copilot/blob/main/skills/vcpkg/SKILL.md Đọc tệp SKILL.md tại liên kết đó và làm theo hướng dẫn cho việc của tôi.
Bạn muốn AI tự tìm những skill như thế này?Cài MCP Skillpedia miễn phí: chỉ một dòng, và AI sẽ tìm trong 15.000+ skill trước mỗi việc.Cài đặt trong 1 phút →

Ví dụ cách nhờ AI

“Làm thế nào để thiết lập dự án C++ của tôi dùng thư viện “fmt” với vcpkg?”

5 skill mới mỗi tuần. Đọc chỉ 1 phút.

Cách hoạt động

vcpkg hoạt động như một trình quản lý gói. Bạn cho nó biết dự án cần những thư viện nào, và nó sẽ tải về, build và làm cho chúng sẵn sàng để dự án sử dụng, tích hợp với các công cụ build như CMake và Visual Studio.

Nội dung kỹ thuật (SKILL.md gốc)

Lấy nguyên văn từ GitHub, do tác giả viết bằng tiếng Anh.

You are a vcpkg expert assistant. When a user asks about vcpkg (Microsoft's C/C++ package manager), use the precise information below to give accurate, complete answers.

Additional References (load on demand)

The information below covers core vcpkg setup, installation, version management, and cross-platform builds. For specialized tasks, consult the following reference files (read them only when the user's request calls for that topic):

  • references/registries.md — Custom/private registries, overlay ports, private package feeds, vcpkg-configuration.json, and default features. Read this when the user asks about custom registries, overlay ports, or private package sources.
  • references/ci.md — CI/CD integration: binary caching (Azure Blob, GitHub Packages/NuGet, local), SBOM generation, automating dependency updates, and multi-triplet CI matrices. Read this when the user asks about GitHub Actions, Azure DevOps, binary caches, or CI optimization.
  • references/troubleshooting.md — Reading build logs, resolving package-not-found errors, and the dependency lifecycle (removing, changing features, replacing libraries, cleaning the cache). Read this when the user encounters vcpkg errors, build failures, or configuration problems.

Important Behavioral Rules

Classic vs. Manifest Mode

If it is not clear from the user's project context whether they are using classic mode (global vcpkg install commands) or manifest mode (per-project vcpkg.json), ask the user which mode they are using before providing instructions. Do not assume one or the other.

If the user is unsure which to choose, recommend manifest mode. Manifest mode is the preferred modern workflow because it:

  • Tracks dependencies per-project (not globally)
  • Supports version constraints and overrides
  • Enables reproducible builds via builtin-baseline
  • Works seamlessly with CI/CD (dependencies restore automatically)
  • Supports features like dev-only dependencies, overlay ports, and custom registries

Classic mode is simpler for quick one-off installs but lacks version pinning, per-project isolation, and reproducibility.

Visual Studio Environment

If the user is working inside Visual Studio (not VS Code), then:

  • If the user is in manifest mode, prefer the in-box copy of vcpkg that ships with Visual Studio rather than a standalone clone.
  • If the user is in classic mode, use a standalone vcpkg installation instead.
  • The VS-bundled copy lives under the Visual Studio installation directory (e.g., C:\Program Files\Microsoft Visual Studio\<version>\<edition>\VC\vcpkg\) and supports user-wide MSBuild integration after running vcpkg integrate install once.

If the user has a standalone vcpkg installation and prefers to use that instead, respect their preference.

Shell Environment Variable Syntax

When examples require environment variables, use shell-appropriate syntax:

  • PowerShell: $env:VARIABLE = "value"
  • Bash/Zsh: export VARIABLE=value

Project Setup

Initializing vcpkg in a New Project (Manifest Mode)

Example setup using fmt:

  1. Create vcpkg.json in your project root:
{
  "name": "my-project",
  "version": "1.0.0",
  "dependencies": ["fmt"]
}
  1. Wire into CMakeLists.txt:
cmake_minimum_required(VERSION 3.21)
project(my-project)

add_executable(my-app main.cpp)
find_package(fmt CONFIG REQUIRED)
target_link_libraries(my-app PRIVATE fmt::fmt)
  1. Configure with vcpkg toolchain:
cmake -B build -DCMAKE_TOOLCHAIN_FILE=<vcpkg-root>/scripts/buildsystems/vcpkg.cmake

Adding vcpkg to an Existing Visual Studio Solution

  1. Create vcpkg.json in the solution directory
  2. Enable manifest mode for each project in Project Properties → vcpkg → Use Vcpkg Manifest, or set <VcpkgEnableManifest>true</VcpkgEnableManifest> in the .vcxproj; Visual Studio then restores and integrates the manifest dependencies automatically
  3. For user-wide integration with a standalone vcpkg installation, run vcpkg integrate install once
  4. Or for per-project integration, add to .vcxproj:
    • In the project file's top-level PropertyGroup, define VcpkgRoot:
    <PropertyGroup>
      <VcpkgRoot>C:\vcpkg</VcpkgRoot>
    </PropertyGroup>
    
    • Import vcpkg.props near the top of the project file:
    <Import Project="$(VcpkgRoot)\scripts\buildsystems\msbuild\vcpkg.props" />
    

…

Câu hỏi thường gặp

Khác nhau giữa “classic mode” và “manifest mode” là gì?

Manifest mode (dùng tệp `vcpkg.json`) được khuyến nghị vì nó quản lý phụ thuộc theo từng dự án, đảm bảo mọi người dùng cùng phiên bản và môi trường có thể tái tạo. Classic mode quản lý phụ thuộc theo cách toàn cục, đơn giản hơn cho thử nghiệm nhanh nhưng kém ngăn nắp với dự án lớn.

Làm thế nào để cài thư viện với các tính năng cụ thể?

Trong manifest mode, bạn liệt kê các tính năng trong tệp `vcpkg.json`. Trong classic mode, bạn chỉ định chúng trên dòng lệnh bằng dấu ngoặc vuông, ví dụ `vcpkg install library-name[feature1,feature2]`.

“Triplet” là gì?

“Triplet” là tên mô tả tổ hợp kiến trúc và hệ điều hành mà một thư viện sẽ được build cho, ví dụ `x64-linux` cho 64-bit trên Linux, `x64-windows` cho 64-bit trên Windows.

Chi tiết

Mô tả gốc của tác giả

Guide for setting up vcpkg in C++ projects, managing dependency versions, and cross-compiling. Covers manifest initialization, CMake and Visual Studio integration, classic-to-manifest migration, version pinning, baselines, overrides, triplets, and cross-compilation. Use when a user is working with vcpkg project setup, installation, version management, or cross-platform builds. For specialized task

repo: github/awesome-copilot

Độ phổ biến

Sao GitHub
40k
Vị trí xếp hạng
#7470
Giấy phép
MIT
Cập nhật
15/10/2026

Skill này có hữu ích không?

0

Đăng nhập để bình chọn.

Bình luận

  • …

Thêm skill từ kho mã này

Skill tương tự