Skip to content

Commit 1676b0b

Browse files
authored
docs: update how to use (#10)
1 parent aa369de commit 1676b0b

File tree

12 files changed

+451
-178
lines changed

12 files changed

+451
-178
lines changed

TODO.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,3 +51,4 @@
5151
- [ ] 将项目迁移到 C++20 模块系统,提升编译速度和模块化程度。
5252
- [ ] 确保与现有构建系统(如 CMake)的兼容性。
5353

54+
- [ ] 解决 404 页面不能正确显示的问题
File renamed without changes.
File renamed without changes.

docs/source/async_io.md renamed to docs/source/contributing/03-async-io-internals.md

File renamed without changes.
File renamed without changes.

docs/source/guides/01-getting-started.md

Lines changed: 50 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# 快速上手
22

3-
本章节将指导你完成 `koroutine_lib` 的配置、构建,并编写你的第一个协程程序。
3+
本章节将指导你如何将 `koroutine_lib` 集成到你的项目中,并编写你的第一个协程程序。
44

55
## 1. 环境要求
66

@@ -11,34 +11,67 @@
1111
- **依赖库**:
1212
- **Linux**: `liburing` (用于异步 I/O)
1313
- **构建系统**: CMake 3.20+
14-
- **Python**: 用于文档生成 (可选)。
1514

16-
## 2. 构建项目
15+
## 2. 集成方式 (推荐)
1716

18-
```bash
19-
# 1. 克隆仓库
20-
git clone https://github.com/King-sj/koroutine_lib.git
21-
cd koroutine_lib
17+
我们推荐直接使用 Release 包中的预编译库和头文件进行集成。这种方式配置简单,编译速度快。
2218

23-
# 2. 配置 CMake
24-
# -S . 指定源码根目录
25-
# -B build 指定构建输出目录
26-
cmake -S . -B build -DCMAKE_BUILD_TYPE=Debug
19+
### 目录结构
2720

28-
# 3. 编译
29-
cmake --build build
21+
假设你下载并解压了 Release 包,目录结构如下:
22+
23+
```text
24+
project_root/
25+
├── pkg/
26+
│ ├── include/ # 原始头文件
27+
│ ├── single_header/ # 单文件头文件 (推荐)
28+
│ └── lib/ # 静态库 (libkoroutinelib.a)
29+
├── src/
30+
│ └── main.cpp
31+
└── CMakeLists.txt
3032
```
3133

32-
编译成功后,你会在 `build/bin` 目录下找到所有的可执行文件(demos 和 tests)。
34+
### CMake 配置
35+
36+
在你的 `CMakeLists.txt` 中添加以下配置:
37+
38+
```cmake
39+
cmake_minimum_required(VERSION 3.20)
40+
project(my_app)
41+
42+
set(CMAKE_CXX_STANDARD 23)
43+
set(CMAKE_CXX_STANDARD_REQUIRED ON)
44+
45+
# 设置包路径
46+
set(PKG_DIR "${CMAKE_SOURCE_DIR}/pkg")
47+
48+
# 包含头文件 (推荐使用 single_header)
49+
include_directories(${PKG_DIR}/single_header)
50+
51+
# 链接库目录
52+
link_directories(${PKG_DIR}/lib)
53+
54+
add_executable(my_app src/main.cpp)
55+
56+
# 链接 koroutinelib
57+
# Linux 下通常还需要链接 pthread 和 dl
58+
target_link_libraries(my_app PRIVATE koroutinelib)
59+
if(UNIX AND NOT APPLE)
60+
target_link_libraries(my_app PRIVATE pthread dl)
61+
endif()
62+
```
3363

3464
## 3. 你的第一个协程
3565

3666
让我们编写一个简单的程序,它启动一个协程,异步地返回一个字符串。
3767

3868
```cpp
39-
#include "koroutine/koroutine.h"
69+
// 使用单文件头文件
70+
#include "koroutine.hpp"
4071
#include <iostream>
4172

73+
using namespace koroutine;
74+
4275
// 定义一个返回 std::string 的协程任务
4376
Task<std::string> get_greeting() {
4477
std::cout << "协程开始执行 on thread " << std::this_thread::get_id() << std::endl;
@@ -60,9 +93,7 @@ int main() {
6093
}
6194
```
6295

63-
将以上代码保存为 `my_first_coro.cpp`,并修改 `demos/CMakeLists.txt` 添加新的可执行目标,然后重新编译。
64-
65-
运行它,你会看到类似以下的输出:
96+
编译并运行它,你会看到类似以下的输出:
6697

6798
```
6899
协程开始执行 on thread 0x16f787000
@@ -74,3 +105,4 @@ int main() {
74105
恭喜!你已经成功运行了你的第一个 `koroutine_lib` 程序。
75106

76107
在下一章节,我们将深入探讨 `Task` 的更多用法。
108+

0 commit comments

Comments
 (0)