CPP Build Systems & Package Management 3 — Questions and Answers
Question 1: Which file does vcpkg use in manifest mode to declare a project's dependencies?
- CMakeLists.txt
- conanfile.txt
- vcpkg.json (Correct answer)
- package.json
Correct answer: vcpkg.json
In vcpkg manifest mode, `vcpkg.json` in the project root lists all required packages and version constraints.
Question 2: What is a CMake `INTERFACE` library primarily used for?
- Building shared libraries with no source files
- Propagating usage requirements (includes, defines) to consumers without compiling any sources (Correct answer)
- Creating header-only static archives
- Defining plugin entry points
Correct answer: Propagating usage requirements (includes, defines) to consumers without compiling any sources
An INTERFACE library has no compiled output but can carry properties like include paths and compile options that propagate to linking targets.
Question 3: In Ninja build system, what command displays a list of all available build targets?
- ninja --list
- ninja -t targets (Correct answer)
- ninja --show-targets
- ninja targets all
Correct answer: ninja -t targets
`ninja -t targets` (using the targets tool) prints all targets defined in the build.ninja file.
Question 4: What does `cmake --build . --target install` do after a successful configure step?
- Configures the project again before installing
- Builds the project and then runs the install rules to copy files to CMAKE_INSTALL_PREFIX (Correct answer)
- Only validates the install manifest
- Removes existing installed files before reinstalling
Correct answer: Builds the project and then runs the install rules to copy files to CMAKE_INSTALL_PREFIX
The `install` target compiles the project (if needed) and then copies artifacts to the directory specified by `CMAKE_INSTALL_PREFIX`.
Question 5: Which Conan command generates a `conanfile.txt` dependency graph visualization?
- conan graph info (Correct answer)
- conan inspect
- conan dependency tree
- conan list --graph
Correct answer: conan graph info
`conan graph info` displays the dependency graph including all transitive dependencies and their resolved versions.
Question 6: In CMake, `CMAKE_BUILD_TYPE` is only meaningful for which type of generator?
- Multi-configuration generators like Visual Studio
- Single-configuration generators like Unix Makefiles and Ninja (Correct answer)
- Xcode generators only
- All generators equally
Correct answer: Single-configuration generators like Unix Makefiles and Ninja
Single-configuration generators (Makefile, Ninja) rely on `CMAKE_BUILD_TYPE` at configure time; multi-config generators select the build type at build time.
Question 7: What is the role of `pkg-config` in a C++ build workflow on Linux?
- It compiles packages from source automatically
- It provides compile and link flags for installed libraries via `.pc` files (Correct answer)
- It manages package versions in a lock file
- It replaces CMake's find_package mechanism entirely
Correct answer: It provides compile and link flags for installed libraries via `.pc` files
`pkg-config` reads `.pc` metadata files installed with libraries and outputs the correct `-I` and `-l` flags for the compiler.
Which file does vcpkg use in manifest mode to declare a project's dependencies?