Skip to content

Instantly share code, notes, and snippets.

@siuoly
Created January 9, 2022 11:38
Show Gist options
  • Save siuoly/d8d87604396856612ad48a3ddab0b5ca to your computer and use it in GitHub Desktop.
Save siuoly/d8d87604396856612ad48a3ddab0b5ca to your computer and use it in GitHub Desktop.
vcpkg first usage

dowload repo

  1. git clone https://github.com/microsoft/vcpkg
  2. alias vcpkg='your/path/about/vcpkg" # for later frequently call
  3. vcpkg install abseil # here is a example.

skip

here skip basic cmake usage.

make a simple repo

ls build a.cc CMakeLists.txt

this is a example for using the google abseil liburary. notice following include "absl/strings/str_join.h" statement.

// https://abseil.io/docs/cpp/quickstart
#include <iostream>
#include <string>
#include <vector>

#include "absl/strings/str_join.h"

int main() {
  std::vector<std::string> v = {"foo", "bar", "baz"};
  std::string s = absl::StrJoin(v, "-");

  std::cout << "Joined string: " << s << "\n";

  return 0;
}

CMakeLists.txt

# general statement
cmake_minimum_required(VERSION 3.5)

# this line make cmake command, find the setting file. For vcpkg setting.
set( CMAKE_TOOLCHAIN_FILE /home/siuoly/projects/c++/vcpkg/vcpkg/scripts/buildsystems/vcpkg.cmake )

# general statement   # Set the project name
project (hello_cmake)

# notice !!!!  For find the command, type `vcpkg install abseil`.
find_package(absl CONFIG REQUIRED)

# Add an executable
# general usage. create "main" executable file.  Using "a.cc" source file.
add_executable( main a.cc )

# notice!!! 
target_link_libraries(main PRIVATE absl::strings )

target_link_libraries(main PRIVATE absl::strings ) For previous #include "absl/strings/str_join.h" statement. Include "absl/strings", so cmake call "absl::strings". if Include "absl/xyz", camke call "absl::xyz".

find_package(absl CONFIG REQUIRED) For finding this command, type vcpkg install abseil. It will just prompt the following message

find_package(absl CONFIG REQUIRED)
Note: 133 target(s) were omitted. target_link_libraries(main PRIVATE absl::any absl::base absl::bits absl::city)

run

cmake . # create a file, named 'makefile'  
make    # using previous 'makefile' ,create executable file
./main  # 
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment