Skip to content

Commit 52277c6

Browse files
committed
Expand application tutorial
1 parent 2a4d9fc commit 52277c6

File tree

1 file changed

+29
-3
lines changed

1 file changed

+29
-3
lines changed

README.md

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ C++ client for [ClickHouse](https://clickhouse.com/).
2626

2727
## Dependencies
2828
In the most basic case one needs only:
29-
- C++-17 complaint compiler (e.g. Clang-6, GCC-7)
30-
- `cmake` (3.20 or newer)
29+
- a C++-17-complaint compiler,
30+
- `cmake` (3.12 or newer), and
3131
- `ninja`
3232

3333
Optional dependencies:
@@ -51,7 +51,14 @@ Plese refer to the workflows for the reference on dependencies/build options
5151
- https://github.com/ClickHouse/clickhouse-cpp/blob/master/.github/workflows/macos.yml
5252

5353

54-
## Example
54+
## Example application build with clickhouse-cpp
55+
56+
There are various ways to integrate clickhouse-cpp with the build system of an application. Below example uses the simple approach based on
57+
submodules presented in https://www.youtube.com/watch?v=ED-WUk440qc .
58+
59+
- `mkdir clickhouse-app && cd clickhouse-app && git init`
60+
- `git submodule add https://github.com/ClickHouse/clickhouse-cpp.git contribs/clickhouse-cpp`
61+
- `touch app.cpp`, then copy the following C++ code into that file
5562

5663
```cpp
5764
#include <iostream>
@@ -100,8 +107,27 @@ int main()
100107

101108
return 0;
102109
}
110+
111+
- `touch CMakeLists.txt`, then copy the following CMake code into that file
112+
113+
```cmake
114+
cmake_minimum_required(VERSION 3.12)
115+
project(application-example)
116+
117+
set(CMAKE_CXX_STANDARD 17)
118+
119+
add_subdirectory(contribs/clickhouse-cpp)
120+
121+
add_executable(${PROJECT_NAME} "app.cpp")
122+
123+
target_include_directories(${PROJECT_NAME} PRIVATE contribs/clickhouse-cpp/ contribs/clickhouse-cpp/contrib/absl)
124+
125+
target_link_libraries(${PROJECT_NAME} PRIVATE clickhouse-cpp-lib)
103126
```
104127
128+
- run `rm -rf build && cmake -B build -S . && cmake --build build -j32` to remove remainders of the previous builds, run CMake and build the
129+
application. The generated binary is located in location `build/application-example`.
130+
105131
## Thread-safety
106132
⚠ Please note that `Client` instance is NOT thread-safe. I.e. you must create a separate `Client` for each thread or utilize some synchronization techniques. ⚠
107133

0 commit comments

Comments
 (0)