Skip to content

Commit cda43b2

Browse files
committed
Expand application tutorial
1 parent 2a4d9fc commit cda43b2

File tree

1 file changed

+31
-3
lines changed

1 file changed

+31
-3
lines changed

README.md

Lines changed: 31 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,13 @@ 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+
- `touch app.cpp`, then copy the following C++ code into that file
5561

5662
```cpp
5763
#include <iostream>
@@ -100,8 +106,30 @@ int main()
100106

101107
return 0;
102108
}
109+
110+
- `touch CMakeLists.txt`, then copy the following CMake code into that file
111+
112+
```cmake
113+
cmake_minimum_required(VERSION 3.12)
114+
project(application-example)
115+
116+
set(CMAKE_CXX_STANDARD 17)
117+
118+
add_subdirectory(contribs/clickhouse-cpp)
119+
120+
add_executable(${PROJECT_NAME} "app.cpp")
121+
122+
target_include_directories(${PROJECT_NAME} PRIVATE contribs/clickhouse-cpp/ contribs/clickhouse-cpp/contrib/absl)
123+
124+
target_link_libraries(${PROJECT_NAME} PRIVATE clickhouse-cpp-lib)
103125
```
104126
127+
- run `rm -rf build && cmake -B build -S . && cmake --build build -j32` to remove remainders of the previous builds, run CMake and build the
128+
application. The generated binary is located in location `build/application-example`.
129+
130+
- `git init`
131+
- `git submodule add https://github.com/ClickHouse/clickhouse-cpp.git contribs/clickhouse-cpp`
132+
105133
## Thread-safety
106134
⚠ 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. ⚠
107135

0 commit comments

Comments
 (0)