- git clone https://github.com/microsoft/vcpkg
- alias vcpkg='your/path/about/vcpkg" # for later frequently call
- vcpkg install abseil # here is a example.
here skip basic cmake usage.
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 #