{"id":49019326,"url":"https://github.com/zxffffffff/start-cpp-vcpkg","last_synced_at":"2026-04-19T03:11:44.473Z","repository":{"id":93054317,"uuid":"582495710","full_name":"zxffffffff/start-cpp-vcpkg","owner":"zxffffffff","description":"一个 C++ 跨平台脚手架项目，使用 vcpkg + cmake 搭建","archived":false,"fork":false,"pushed_at":"2025-03-18T07:17:54.000Z","size":11217,"stargazers_count":8,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-18T08:27:25.950Z","etag":null,"topics":["cmake","corss-platform","cpp","starter","template","vcpkg"],"latest_commit_sha":null,"homepage":"","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/zxffffffff.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-12-27T02:42:31.000Z","updated_at":"2025-03-18T07:17:36.000Z","dependencies_parsed_at":"2023-11-03T10:28:57.168Z","dependency_job_id":"57a5b6d3-f04e-4a73-9b3e-f36a027b031c","html_url":"https://github.com/zxffffffff/start-cpp-vcpkg","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/zxffffffff/start-cpp-vcpkg","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zxffffffff%2Fstart-cpp-vcpkg","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zxffffffff%2Fstart-cpp-vcpkg/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zxffffffff%2Fstart-cpp-vcpkg/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zxffffffff%2Fstart-cpp-vcpkg/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/zxffffffff","download_url":"https://codeload.github.com/zxffffffff/start-cpp-vcpkg/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zxffffffff%2Fstart-cpp-vcpkg/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31992902,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-18T20:23:30.271Z","status":"online","status_checked_at":"2026-04-19T02:00:07.110Z","response_time":55,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cmake","corss-platform","cpp","starter","template","vcpkg"],"created_at":"2026-04-19T03:11:43.782Z","updated_at":"2026-04-19T03:11:44.460Z","avatar_url":"https://github.com/zxffffffff.png","language":"C++","readme":"# start-cpp-vcpkg\n\n![workflow](https://github.com/zxffffffff/start-cpp-vcpkg/actions/workflows/build-windows.yml/badge.svg?event=push)\n![workflow](https://github.com/zxffffffff/start-cpp-vcpkg/actions/workflows/build-macos.yml/badge.svg?event=push)\n![workflow](https://github.com/zxffffffff/start-cpp-vcpkg/actions/workflows/build-ubuntu.yml/badge.svg?event=push)\n\n从模板创建仓库: [start-cpp-vcpkg-template](https://github.com/zxffffffff/start-cpp-vcpkg-template)\n\n## 温馨提示\n\n- 可以使用环境变量 VCPKG_ROOT、VCPKG_DOWNLOADS 指定安装、下载目录，也可以每个项目自带一个 vcpkg 子模块\n- 下载时网络不是很稳定，经常失败需要反复手动下载，建议仅开源项目和小型项目使用\n- 叫得出名字的库基本都支持，如果 vcpkg search 没有那就真没有了\n\n## 一个 C++ 跨平台脚手架项目，使用 vcpkg + cmake 搭建\n\n- sample-tools\n  - `gflags`: Google 命令行标志库。\n  - `glog`: Google 日志库。\n  - `boost`: 标准库，可以按需单独安装某个库。\n  - `zlib`: 最流行的数据压缩库。\n  - `snappy`: Google 快速压缩库。\n  - `sqlite3`: 最流行的嵌入式关系数据库。\n  - `cryptopp`: 密码学库，支持 base64/RSA/AES 等常用加密算法。\n  - `rapidjson`: 腾讯出品，高性能 JSON 解析/生成器，灵感来自 RapidXml。\n  - `nlohmann-json`: 现代的 JSON 解析/生成器，语法糖非常方便。\n  - `tinyxml`: 轻量的 XML 解析库。\n  - `fmt`: 格式化库，实现 C++20 std::format，完美取代 iostreams 和 printf。\n- sample-db\n  - `mysql-connector-cpp`: 连接 MySQL 数据库。\n  - `mongo-cxx-driver`: 连接 MongoDB 数据库。\n  - `hiredis`: 连接 Redis 数据库。\n- sample-pb\n  - `protobuf`: Google 数据序列化库。\n- sample-net\n  - `libcurl`: 最流行的多协议文件传输库，支持 HTTP 请求。\n  - `libuv`: node.js 跨平台异步I/O，支持 TCP/UDP sockets。\n- sample-test\n  - `gtest`: Google 测试框架。\n\n## 快速开始\n\n- 运行 `build-xxx` 在线安装第三方库，需要能够访问外网 (github)\n- 网络异常导致的错误，可以尝试重新运行脚本(下载较多，可能需要反复重试)\n- 跨平台项目建议使用 静态库 (Linux默认静态编译，动态链接系统库)\n- 跨平台项目建议使用 UTF-8 编码格式，这样仅需设置 Windows 编译环境 (Windows 中文系统默认使用 GBK 编码)\n- 跨平台项目建议使用 `.gitattributes` 确保提交时转换为 `LF`\n\n### 已验证\n\n- macOS 14.5 (arm64-osx)\n- Windows 10 (x64-windows)\n- Ubuntu 24.04 (x64-linux)\n\n### 编译器最低版本建议\n\n| C++ compiler  | Minimum OS version |\n| ------------- | ------------------ |\n| MSVC v140     | Windows 7          |\n| Clang 12      | macOS 10.15        |\n| GCC 7.3       | Ubuntu 18.04       |\n\n### CMake CXX_STANDARD 版本参考\n\n| Added in version  | C++ Standard    |\n| ----------------- | --------------- |\n| 3.1               | C++ 98, 11, 14  |\n| 3.8               | C++ 17          |\n| 3.12              | C++ 20          |\n| 3.20              | C++ 23          |\n| 3.25              | C++ 26          |\n\n### Windows MSVC 参考\n\n| CMake version         | MSVC version    |\n| --------------------- | --------------- |\n| Visual Studio 17 2022 | v143            |\n| Visual Studio 16 2019 | v142            |\n| Visual Studio 15 2017 | v141            |\n| Visual Studio 14 2015 | v140            |\n| Visual Studio 12 2013 | 不保证二进制兼容性 |\n\n### Apple C++ 版本参考\n\n| C++ Feature        | Minimum deployment target                     |\n| ------------------ | --------------------------------------------- |\n| C++ 17 Filesystem  | macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0 |\n\n### Linux Glibc 版本参考\n\n| Glibc | Ubuntu             | CentOS         | Debian          |\n| ----- | ------------------ | -------------- | --------------- |\n| 2.35  | 22.04 (GCC 11.2.0) |                |                 |\n| 2.34  |                    | 9 (GCC 11.2.1) |                 |\n| 2.31  | 20.04 (GCC 9.3.0)  |                | 11 (GCC 10.2.1) |\n| 2.28  |                    | 8 (GCC 8.3.1)  | 10 (GCC 8.3.0)  |\n| 2.27  | 18.04 (GCC 7.3.0)  |                |                 |\n| 2.24  |                    |                | 9 (GCC 6.3.0)   |\n| 2.23  | 16.04 (GCC 5.4.0)  |                |                 |\n| 2.19  | 14.04 (GCC 4.8.2)  |                | 8 (GCC 4.9.2)   |\n| 2.17  |                    | 7 (GCC 4.8.5)  |                 |\n| 2.15  | 12.04 (GCC 4.6.3)  |                |                 |\n| 2.13  |                    |                | 7 (GCC 4.7.2)   |\n| 2.12  |                    | 6 (GCC 4.4.7)  |                 |\n\n## 注意事项\n\n### Windows 7 版本兼容\n\n- `VS 2022 17.9` 以后无法使用 `vcpkg` 编译旧版本 `boost`：\u003chttps://github.com/microsoft/vcpkg/issues/38980\u003e\n- `Electron 22.x` 依赖项 -\u003e `node-gyp 10.x` -\u003e `Python 3.11` 以后无法编译 `C++ Addons`：\u003chttps://github.com/nodejs/node-gyp/issues/2869\u003e\n\n### Windows 宏定义冲突\n\n- `min` `max` 等冲突报错可以 `#undef` 解决\n\n### macOS 三方库错误\n\n- `mysql-connector-cpp` 和 `protobuf` 同时引用bug，注意避免: \u003chttps://github.com/microsoft/vcpkg/issues/27873\u003e\n- `mysql-connector-cpp` 构建错误bug，注意避免: \u003chttps://github.com/microsoft/vcpkg/issues/32878\u003e\n\n### Linux 打包\n\n- 使用 `-static-libgcc -static-libstdc++` 静态编译 C++\n- 不能使用 `-static` 静态编译 C，需要注意开发环境使用低版本 `glibc` 编译动态链接\n\n### Protobuf 静态链接\n\n- 注意编译 `.proto` 文件必须使用 `libprotobuf` 相同版本\n- Windows 下静态链接 `.pb.cc` 等文件需要静态编译 `libprotobuf`\n\n### vcpkg 指定编译器(降级)\n\n- 除了使用 `cmake -G` 之外，还需要在 `vcpkg/triplets/xxx.cmake` 指定编译器，否则默认使用已安装的最新版本\n- 手动修改 triplets 配置，例如设置 MSVC 版本 `set(VCPKG_PLATFORM_TOOLSET v140)`\n\n### vcpkg 指定版本号(降级)\n\n- 必须使用 `git clone` 或 `submodule` 引入 vcpkg，`subtree` 会报错找不到 `.git` 文件\n- 查看历史版本：`git blame -l versions/l-/libuv.json`\n- 自动添加baseline：`vcpkg x-update-baseline --add-initial-baseline`\n\n```js\n// libuv 1.41 是最后一个支持 win7 的版本\n\"overrides\": [\n  {\n    \"name\": \"libuv\",\n    \"version\": \"1.41.0\",\n    \"port-version\": 1\n  }\n],\n\"builtin-baseline\": \"b051745c68faa6f65c493371d564c4eb8af34dad\"\n```\n\n## Vcpkg\n\n- 安装 `vcpkg` 参考本工程 `CMakeLists.txt`\n- 手动安装建议使用 `git clone https://github.com/microsoft/vcpkg.git`\n- 推荐使用环境变量 VCPKG_ROOT、VCPKG_DOWNLOADS 避免重复下载编译\n\n### 参考\n\n- \u003chttps://github.com/microsoft/vcpkg\u003e\n- \u003chttps://github.com/microsoft/vcpkg/blob/master/README_zh_CN.md\u003e\n\n### 查询 \u0026 添加 \u0026 查看\n\n```Bash\n.\\vcpkg\\vcpkg.exe search xxx\n.\\vcpkg\\vcpkg.exe install xxx` or `vcpkg.json\n.\\vcpkg\\packages\\xxx\\CONTROL\n```\n\n### Windows\n\n- Windows 7 或更新的版本\n- Visual Studio 2015 Update 3 或更新的版本 (包含英文语言包)\n- 运行 `bootstrap-vcpkg.bat` 脚本\n\n### Unix\n\n- g++ \u003e= 6\n- macOS:\n\n  ```Bash\n  xcode-select --install\n  brew install pkg-config\n  ```\n\n- Debian，Ubuntu，popOS 或其他基于 Debian 的发行版:\n\n  ```Bash\n  sudo apt-get update\n  sudo apt-get install build-essential tar curl zip unzip\n  ```\n\n- CentOS:\n\n  ```Bash\n  sudo yum install centos-release-scl\n  sudo yum install devtoolset-7\n  scl enable devtoolset-7 bash\n  ```\n\n- 运行 `bootstrap-vcpkg.sh` 脚本\n\n### Triplet 可选编译配置集\n\n- \u003chttps://learn.microsoft.com/en-us/vcpkg/users/triplets\u003e\n- 在经典模式下，您可以使用三元组名称限定包引用，例如 `zlib:x64-windows-static-md`\n- 在Manifest模式下，可以在命令行传递 `vcpkg install --triplet=\u003ctriplet\u003e`\n- 使用 CMake，您可以设置 `set(VCPKG_TARGET_TRIPLET \u003ctriplet\u003e)`\n- 查看三元组 `vcpkg help triplet`\n- 可以手动修改 triplets 配置\n\n```\nBuilt-in Triplets:\n  x64-android\n  x64-linux\n  arm64-osx\n  x64-windows\n  arm64-uwp\n  x64-windows-static\n  x86-windows\n  arm-neon-android\n  arm64-windows\n  x64-uwp\n  x64-osx\n  arm64-android\nCommunity Triplets:\n  wasm32-emscripten\n  x64-xbox-scarlett-static\n  ppc64le-linux\n  ...\n  ppc64le-linux-release\n  x86-windows-v120\n  arm-uwp\n```\n\n## License\n\n选择合适的开源协议，例如 `MIT License`\n\n![image](https://github.com/zxffffffff/start-cpp-vcpkg/blob/main/docs/choose-a-license.png)\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzxffffffff%2Fstart-cpp-vcpkg","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fzxffffffff%2Fstart-cpp-vcpkg","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzxffffffff%2Fstart-cpp-vcpkg/lists"}