자습서: 명령줄에서 종속성 설치
팁
종속성을 설치하는 권장 방법은 "매니페스트 파일에서 종속성 설치" 참조하세요.
경고
일부 vcpkg 기능은 클래식 모드에서 사용할 수 없습니다.
vcpkg에는 클래식 모드와 매니페스트 모드의 두 가지 작업 모드가 있습니다. 이 문서에서는 클래식 모드를 사용하여 패키지를 설치하는 방법을 설명합니다. 대부분의 사용자에게는 매니페스트 모드를 대신 사용하는 것이 좋습니다.
클래식 모드에서는 vcpkg를 명령줄 인터페이스로 사용하여 일반적인 설치 디렉터리종속성을 설치합니다. 일반적으로 %VCPKG_ROOT%/installed
위치하며, 여기서 %VCPKG_ROOT%
vcpkg의 설치 디렉터리입니다.
이 자습서에서는 다음을 알아봅니다.
필수 구성 요소
- vcpkg
- 터미널
- 코드 편집기
- C++ 컴파일러
- (선택 사항) CMake 또는 MSBuild
1 - 프로젝트 만들기
새 폴더에서 다음 내용이 포함된 main.cxx
원본 파일을 만듭니다.
#include <cxxopts.hpp>
#include <fmt/format.h>
#include <range/v3/view.hpp>
namespace view = ranges::views;
int fib(int x)
{
int a = 0, b = 1;
for (int it : view::repeat(0) | view::take(x))
{
(void)it;
int tmp = a;
a += b;
b = tmp;
}
return a;
}
int main(int argc, char **argv)
{
cxxopts::Options options("fibo", "Print the fibonacci sequence up to a value 'n'");
options.add_options()("n,value", "The value to print to", cxxopts::value<int>()->default_value("10"));
auto result = options.parse(argc, argv);
auto n = result["value"].as<int>();
for (int x : view::iota(1) | view::take(n))
{
fmt::print("fib({}) = {}\n", x, fib(x));
}
}
이 코드는 cxxopts
, fmt
및 range-v3
; 오픈 소스 라이브러리를 참조합니다. 모두 https://github.com/Microsoft/vcpkgvcpkg 공용 레지스트리에서 사용할 수 있습니다.
2 - 빌드 시스템과 vcpkg 통합
이 단계에서는 프로젝트를 빌드할 때마다 프로젝트 종속성이 자동으로 설치되거나 복원되도록 vcpkg를 CMake 또는 MSBuild와 통합하는 방법을 보여 줍니다.
다른 빌드 시스템을 사용하는 경우 다음 단계로 건너뜁니다. 종속성 설치.
MSBuild vcpkg 사용에 대해 자세히 알아보기
msBuild 프로젝트 vcpkg를 사용하려면 다음 명령을 실행합니다.
vcpkg integrate install
MSBuild 통합을 처음 사용하도록 설정하려면 vcpkg integrate install
명령을 실행하기만 하면 됩니다. 이렇게 하면 모든 기존 및 향후 프로젝트에 MSBuild 통합이 가능합니다.
vcpkg integrate remove
사용하여 MSBuild 시스템 전체 통합을 제거합니다.
이 통합 메서드는 vcpkg 설치 패키지를 Include Directories
, Link Directories
및 Link Libraries
프로젝트 속성에 자동으로 추가합니다. 또한 필요한 모든 DLL이 빌드 출력 폴더에 복사되도록 하는 빌드 후 작업을 만듭니다. Visual Studio 2015 이상에서 사용하는 모든 솔루션 및 프로젝트에 대해 작동합니다.
3 - 종속성 설치
이 코드는 cxxopts
, fmt
및 range-v3
; 오픈 소스 라이브러리를 참조합니다. 이들은 모두 https://github.com/Microsoft/vcpkgvcpkg 공용 레지스트리에서 사용할 수 있습니다.
이러한 패키지를 설치하려면 vcpkg install
명령을 사용합니다.
vcpkg install cxxopts fmt range-v3
$ ./vcpkg install cxxopts fmt range-v3
Computing installation plan...
The following packages will be built and installed:
cxxopts:x64-windows -> 3.1.1
fmt:x64-windows -> 10.0.0
range-v3:x64-windows -> 0.12.0#1
* vcpkg-cmake:x64-windows -> 2023-05-04
* vcpkg-cmake-config:x64-windows -> 2022-02-06#1
Additional packages (*) will be modified to complete this operation.
(omitted)
cxxopts provides CMake targets:
# this is heuristically generated, and may not be correct
find_package(cxxopts CONFIG REQUIRED)
target_link_libraries(main PRIVATE cxxopts::cxxopts)
The package fmt provides CMake targets:
find_package(fmt CONFIG REQUIRED)
target_link_libraries(main PRIVATE fmt::fmt)
# Or use the header-only version
find_package(fmt CONFIG REQUIRED)
target_link_libraries(main PRIVATE fmt::fmt-header-only)
range-v3 provides CMake targets:
# this is heuristically generated, and may not be correct
find_package(range-v3 CONFIG REQUIRED)
target_link_libraries(main PRIVATE range-v3::meta range-v3::concepts range-v3::range-v3)
4 - 프로젝트 빌드
중요하다
설치된 패키지의 삼중 프로젝트의 구성과 일치하는지 확인합니다. 64비트 프로젝트에 x64-windows
또는 x64-windows-static
사용하고 32비트 프로젝트에 x86-windows
또는 x86-windows-static
사용합니다.
시스템 전체 통합을 사용하도록 설정하면 msbuild
실행하여 프로젝트를 빌드합니다.
PS D:\projects\manifest-example> msbuild
MSBuild version 17.7.0-preview-23319-02+6829506b8 for .NET Framework
Build started 8/13/2023 3:07:36 PM.
Project "D:\projects\manifest-example\manifest-example.sln" on node 1 (default targets).
ValidateSolutionConfiguration:
(omitted)
PrepareForBuild:
(omitted)
InitializeBuildStatus:
(omitted)
ComputeStdModulesCompileInputs:
(omitted)
SetModuleDependencies:
VcpkgTripletSelection:
Using triplet "x64-windows" from "D:\vcpkg\installed\x64-windows\"
Using normalized configuration "Debug"
ClCompile:
(omitted)
Link:
(omitted)
AppLocalFromInstalled:
pwsh.exe -ExecutionPolicy Bypass -noprofile -File "D:\vcpkg\scripts\buildsystems\msbuild\applocal.ps1" "D:\projects\manifest-example\x64\Debug\manifest-example.exe"
"D:\vcpkg\installed\x64-windows\debug\bin" "x64\Debug\manifest-example.tlog\manifest-example.write.1u.tlog" "x64\Debug\vcpkg.applocal.log"
D:\projects\manifest-example\x64\Debug\fmtd.dll
FinalizeBuildStatus:
Deleting file "x64\Debug\manifest-example.tlog\unsuccessfulbuild".
Touching "x64\Debug\manifest-example.tlog\manifest-example.lastbuildstate".
Done Building Project "D:\projects\manifest-example\manifest-example.vcxproj" (default targets).
Done Building Project "D:\projects\manifest-example\manifest-example.sln" (default targets).
Build succeeded.
다음 단계
이 자습서에서는 명령줄 인터페이스로 vcpkg를 사용하여 간단한 프로젝트에 대한 종속성을 설치했습니다.
다음에 시도할 몇 가지 추가 작업은 다음과 같습니다.
- 매니페스트 파일 사용하여 패키지 설치
- 삼중 사용하여 사용자 지정 플랫폼용 패키지 설치
- 버전 관리을 사용하여 반복 가능한 빌드를 위한 버전을 잠급니다.
- 연속 통합 실행 시 이진 캐싱을 사용하여 바이너리를 재사용합니다.
- 사용자 지정 레지스트리를 사용하여 프라이빗 라이브러리 관리
vcpkg