快速开始 - Unix
首先,下载vcpkg, 我们建议您将vcpkg作为cmake项目的子模块使用。以下示例中涉及的命令在unix系统通用,示例使用Linux系统.
usr@usr:/home# git clone https://github.com/microsoft/vcpkg.git
Cloning into 'vcpkg'...
remote: Enumerating objects: 14, done.
remote: Counting objects: 100% (14/14), done.
remote: Compressing objects: 100% (13/13), done.
remote: Total 104557 (delta 2), reused 4 (delta 1), pack-reused 104543
Receiving objects: 100% (104557/104557), 31.88 MiB | 27.30 MiB/s, done.
Resolving deltas: 100% (65552/65552), done.
usr@usr:/home#
此时,您就可以使用 bootstrap.sh 编译vcpkg了。
进入克隆的vcpkg目录中:
usr@usr:/home/# cd vcpkg/
usr@usr:/home/vcpkg#
执行bootstrap-vcpkg.sh脚本编译vcpkg。注意:目前不支持在UNIX中下载vcpkg二进制文件。
usr@usr:/home/vcpkg# ./bootstrap-vcpkg.sh
Downloading cmake...
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 634 100 634 0 0 1474 0 --:--:-- --:--:-- --:--:-- 1474
100 40.9M 100 40.9M 0 0 34.6M 0 0:00:01 0:00:01 --:--:-- 71.5M
Downloading cmake... done.
Extracting cmake...
Extracting cmake... done.
Downloading ninja...
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 619 100 619 0 0 1391 0 --:--:-- --:--:-- --:--:-- 1391
100 99913 100 99913 0 0 163k 0 --:--:-- --:--:-- --:--:-- 3902k
Downloading ninja... done.
Extracting ninja...
Extracting ninja... done.
Downloading vcpkg tool sources
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 173 100 173 0 0 416 0 --:--:-- --:--:-- --:--:-- 416
100 479k 100 479k 0 0 418k 0 0:00:01 0:00:01 --:--:-- 1480k
Building vcpkg-tool...
-- The C compiler identification is GNU 7.5.0
-- The CXX compiler identification is GNU 7.5.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /usr/bin/cc - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/g++-7 - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Detecting the C++ compiler in use
-- Detecting the C++ compiler in use - gcc
-- Detecting the C++ standard library
-- Detecting the C++ standard library - libstdc++
-- Detecting how to use the C++ filesystem library
-- Detecting how to use the C++ filesystem library - <experimental/filesystem> with -lstdc++fs
-- Looking for pthread.h
-- Looking for pthread.h - found
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD - Failed
-- Check if compiler accepts -pthread
-- Check if compiler accepts -pthread - yes
-- Found Threads: TRUE
-- Configuring done
-- Generating done
-- Build files have been written to: /home/vcpkg/buildtrees/_vcpkg/build
[0/2] Re-checking globbed directories...
[88/88] Linking CXX executable vcpkg
Telemetry
---------
vcpkg collects usage data in order to help us improve your experience.
The data collected by Microsoft is anonymous.
You can opt-out of telemetry by re-running the bootstrap-vcpkg script with -disableMetrics,
passing --disable-metrics to vcpkg on the command line,
or by setting the VCPKG_DISABLE_METRICS environment variable.
Read more about vcpkg telemetry at docs/about/privacy.md
usr@usr:/home/vcpkg#
若不想让vcpkg上传遥测数据(仅用于改善vcpkg),请在bootstrap-vcpkg.bat脚本后添加命令-disableMetrics。
至此,我们已经准备好安装vcpkg支持的第三方库了。对于一些安装过程中需要的工具,则会在首次安装库时自动下载。
示例:安装zlib
usr@usr:/home/vcpkg# ./vcpkg install zlib
Computing installation plan...
The following packages will be built and installed:
zlib[core]:x64-linux -> 1.2.11#9
Detecting compiler hash for triplet x64-linux...
Could not locate cached archive: /root/.cache/vcpkg/archives/30/30fa6609a31aac8f82df0671143c9bf16b7580eb.zip
Starting package 1/1: zlib:x64-linux
Building package zlib[core]:x64-linux...
-- Downloading http://www.zlib.net/zlib-1.2.11.tar.gz -> zlib1211.tar.gz...
-- Extracting source /home/vcpkg/downloads/zlib1211.tar.gz
-- Applying patch cmake_dont_build_more_than_needed.patch
-- Applying patch 0001-Prevent-invalid-inclusions-when-HAVE_-is-set-to-0.patch
-- Applying patch add_debug_postfix_on_mingw.patch
-- Using source at /home/vcpkg/buildtrees/zlib/src/1.2.11-63309e48e5.clean
-- Configuring x64-linux-dbg
-- Configuring x64-linux-rel
-- Building x64-linux-dbg
-- Building x64-linux-rel
-- Fixing pkgconfig file: /home/vcpkg/packages/zlib_x64-linux/lib/pkgconfig/zlib.pc
-- Fixing pkgconfig file: /home/vcpkg/packages/zlib_x64-linux/debug/lib/pkgconfig/zlib.pc
-- Installing: /home/vcpkg/packages/zlib_x64-linux/share/zlib/copyright
-- Performing post-build validation
-- Performing post-build validation done
sh: 1: zip: not found
Failed to store binary cache /root/.cache/vcpkg/archives/30/30fa6609a31aac8f82df0671143c9bf16b7580eb.zip: Invalid cross-device link
Building package zlib[core]:x64-linux... done
Installing package zlib[core]:x64-linux...
Installing package zlib[core]:x64-linux... done
Elapsed time for package zlib:x64-linux: 2.143 s
Total elapsed time: 2.382 s
The package zlib is compatible with built-in CMake targets:
find_package(ZLIB REQUIRED)
target_link_libraries(main PRIVATE ZLIB::ZLIB)
usr@usr:/home/vcpkg#
VCPKG 团队期待您的贡献!