https://github.com/marcuwynu23/vcpkg-cmake-cpp-first-project-experiment
My First Experiment in developing and using vcpkg package manager in c++
https://github.com/marcuwynu23/vcpkg-cmake-cpp-first-project-experiment
cpp vcpkg
Last synced: about 2 months ago
JSON representation
My First Experiment in developing and using vcpkg package manager in c++
- Host: GitHub
- URL: https://github.com/marcuwynu23/vcpkg-cmake-cpp-first-project-experiment
- Owner: marcuwynu23
- Created: 2024-02-21T19:51:49.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2024-02-22T13:59:44.000Z (over 1 year ago)
- Last Synced: 2025-09-03T02:47:04.333Z (about 2 months ago)
- Topics: cpp, vcpkg
- Language: C++
- Homepage:
- Size: 2.93 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: Readme.md
Awesome Lists containing this project
README
# How to create c/c++ project using vcpkg
1. create a project folder
```sh
mkdir project
```2. navigate to project folder
```sh
cd project
```3. initialize vcpkg project
```sh
vcpkg new --application
```4. add ports (dependencies. ex. fmt,libssh,boost)
```sh
vckg add port fmt
```5. create cmakelists.txt
```cmake
cmake_minimum_required(VERSION 3.10)# set the project name
project(app)# add the executable
# Include source files from the 'app' directory
file(GLOB APP_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/src/*.cpp")
add_executable(app ${APP_SOURCES})# add header files
target_include_directories(app PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include)# find and link fmt library
find_package(fmt CONFIG REQUIRED)
target_link_libraries(app PRIVATE fmt::fmt)```
6. create CMakePresets.json
```json
{
"version": 3,
"configurePresets": [
{
"name": "default",
"binaryDir": "${sourceDir}/build",
"cacheVariables": {
"CMAKE_TOOLCHAIN_FILE": "$env{VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake"
}
}
]
}
```7. create c/c++ entry point (main.cpp/main.c)
```sh
touch main.cpp
```8. write code in main.cpp
```cpp
#includeint main()
{
fmt::print("Hello World!\n");
return 0;
}
```9. generate build files using cmake based on **CMakePresets.json** configuration.
```sh
cmake --preset=default
```10. build the project
```sh
cmake --build build
```11. run the app
```sh
./build/debug/hello.exe
```