- 创建项目
mkdir demo
cd demo
- 创建 cmake 工程
vi CMakeLists.txt
cmake_minimum_required(VERSION 2.8)
project(demo)
- 引入第三方库
mkdir 3rd
git clone https://github.com/fmtlib/fmt.git 3rd/fmt
- 链接第三方库
vi CMakeLists.txt
cmake_minimum_required(VERSION 2.8)
project(demo)
add_executable(demo main.cpp)
add_subdirectory(3rd/fmt)
target_link_libraries(demo fmt)
- 编写业务逻辑
vi main.cpp
#include <fmt/core.h>
int main()
{
fmt::print("Hello, world!\n");
}
- 项目编译
cmake .
make
- 项目运行
./demo
可以看到控制台输出:
Hello, world!