2020-->
2121# Apache IoTDB C++ Client
2222
23+ [ 中文说明] ( README_zh.md )
24+
25+ This directory builds and packages the Apache IoTDB C++ Session SDK. If you
26+ already have an ` iotdb-session-cpp-<version>-<classifier>.zip ` package, you do
27+ not need Maven, Thrift, Boost, or this source tree to use it in your own
28+ application. Unpack the zip, point your build system at its ` include/ ` and
29+ ` lib/ ` directories, and deploy the IoTDB runtime library with your executable.
30+
31+ ## Use a packaged SDK in your project
32+
33+ ### 1. Pick and unpack the right package
34+
35+ Choose the zip whose classifier matches the machine where the application will
36+ run:
37+
38+ | Target environment | Zip classifier (suffix) |
39+ | --------------------| -------------------------|
40+ | Linux x86_64, glibc >= 2.17 | ` linux-x86_64-glibc2.17 ` |
41+ | Linux aarch64, glibc >= 2.17 | ` linux-aarch64-glibc2.17 ` |
42+ | macOS x86_64 | ` macos-x86_64 ` |
43+ | macOS arm64 | ` macos-aarch64 ` |
44+ | Windows + Visual Studio 2017 | ` windows-x86_64-msvc14.1 ` |
45+ | Windows + Visual Studio 2019 | ` windows-x86_64-msvc14.2 ` |
46+ | Windows + Visual Studio 2022 | ` windows-x86_64-msvc14.3 ` |
47+ | Windows + Visual Studio 2026 | ` windows-x86_64-msvc14.4 ` |
48+
49+ Example:
50+
51+ ``` bash
52+ unzip iotdb-session-cpp-2.0.7-SNAPSHOT-linux-x86_64-glibc2.17.zip
53+ export IOTDB_SESSION_HOME=$PWD /iotdb-session-cpp-2.0.7-SNAPSHOT-linux-x86_64-glibc2.17
54+ ```
55+
56+ The unpacked SDK contains public headers, one runtime library, CMake and
57+ pkg-config metadata, and examples:
58+
59+ ```
60+ include/ public C and C++ API headers
61+ lib/ libiotdb_session.so/.dylib or iotdb_session.dll + .lib
62+ cmake/iotdb-session-config.cmake CMake package config
63+ pkgconfig/iotdb-session.pc pkg-config metadata
64+ examples/ sample source files and an example CMakeLists.txt
65+ third_party/DEPENDENCIES.md bundled third-party dependency notes
66+ ```
67+
68+ Thrift and Boost are embedded into ` iotdb_session ` ; applications do not install
69+ separate Thrift or Boost headers/libraries for normal SDK use.
70+
71+ ### 2. Link with CMake
72+
73+ ``` cmake
74+ cmake_minimum_required(VERSION 3.15)
75+ project(my_iotdb_app LANGUAGES CXX)
76+
77+ set(CMAKE_CXX_STANDARD 11)
78+ set(CMAKE_CXX_STANDARD_REQUIRED ON)
79+
80+ find_package(iotdb-session REQUIRED CONFIG)
81+
82+ add_executable(my_iotdb_app main.cpp)
83+ target_link_libraries(my_iotdb_app PRIVATE IoTDB::iotdb_session)
84+ ```
85+
86+ Configure with the SDK prefix:
87+
88+ ``` bash
89+ cmake -S . -B build -DCMAKE_PREFIX_PATH=" $IOTDB_SESSION_HOME "
90+ cmake --build build
91+ ```
92+
93+ On Windows, use the same Visual Studio generation as the SDK package. For
94+ example, link a ` windows-x86_64-msvc14.3 ` package with Visual Studio 2022.
95+
96+ Visual Studio users can either open the project folder and add the unpacked SDK
97+ directory to ` CMAKE_PREFIX_PATH ` in CMake cache settings, or configure from a
98+ Developer Command Prompt:
99+
100+ ``` bat
101+ cmake -S . -B build -G "Visual Studio 17 2022" -A x64 ^
102+ -DCMAKE_PREFIX_PATH="%IOTDB_SESSION_HOME%"
103+ cmake --build build --config Release
104+ copy "%IOTDB_SESSION_HOME%\lib\iotdb_session.dll" build\Release\
105+ ```
106+
107+ ### 3. Link with pkg-config on Linux/macOS
108+
109+ ``` bash
110+ export PKG_CONFIG_PATH=" $IOTDB_SESSION_HOME /pkgconfig:$PKG_CONFIG_PATH "
111+ c++ -std=c++11 main.cpp $( pkg-config --cflags --libs iotdb-session) -o my_iotdb_app
112+ ```
113+
114+ When running from a directory that does not already know where the shared
115+ library is, either copy the runtime library next to the executable or set the
116+ library search path:
117+
118+ ``` bash
119+ cp -P " $IOTDB_SESSION_HOME " /lib/libiotdb_session.so* .
120+ ./my_iotdb_app
121+
122+ # Or:
123+ LD_LIBRARY_PATH=" $IOTDB_SESSION_HOME /lib:$LD_LIBRARY_PATH " ./my_iotdb_app
124+ ```
125+
126+ ### 4. Link manually
127+
128+ Linux:
129+
130+ ``` bash
131+ c++ -std=c++11 main.cpp \
132+ -I" $IOTDB_SESSION_HOME /include" \
133+ -L" $IOTDB_SESSION_HOME /lib" \
134+ -liotdb_session -pthread \
135+ -Wl,-rpath," $IOTDB_SESSION_HOME /lib" \
136+ -o my_iotdb_app
137+ ```
138+
139+ macOS:
140+
141+ ``` bash
142+ c++ -std=c++11 main.cpp \
143+ -I" $IOTDB_SESSION_HOME /include" \
144+ -L" $IOTDB_SESSION_HOME /lib" \
145+ -liotdb_session \
146+ -Wl,-rpath," $IOTDB_SESSION_HOME /lib" \
147+ -o my_iotdb_app
148+ ```
149+
150+ Windows with MSVC:
151+
152+ ``` bat
153+ cl /std:c++14 /EHsc main.cpp /I "%IOTDB_SESSION_HOME%\include" ^
154+ /link /LIBPATH:"%IOTDB_SESSION_HOME%\lib" iotdb_session.lib
155+ copy "%IOTDB_SESSION_HOME%\lib\iotdb_session.dll" .
156+ ```
157+
158+ ### 5. Build the bundled examples
159+
160+ The package includes example sources under ` examples/ ` . From the unpacked SDK
161+ root:
162+
163+ ``` bash
164+ cmake -S examples -B examples-build -DCMAKE_BUILD_TYPE=Release
165+ cmake --build examples-build
166+ ```
167+
168+ On Windows:
169+
170+ ``` bat
171+ cmake -S examples -B examples-build -G "Visual Studio 17 2022" -A x64
172+ cmake --build examples-build --config Release
173+ ```
174+
175+ The example build copies the IoTDB runtime library next to each example
176+ executable. ` cmake --build examples-build --target example-dist ` also creates a
177+ ` dist/ ` folder containing the examples and runtime library.
178+
179+ ### 6. Minimal C++ program
180+
181+ ``` cpp
182+ #include " Session.h"
183+
184+ #include < iostream>
185+ #include < memory>
186+
187+ int main () {
188+ auto session = std::make_shared<Session >("127.0.0.1", 6667, "root", "root");
189+ session->open(false);
190+
191+ session->setStorageGroup("root.test");
192+ if (!session->checkTimeseriesExists("root.test.d0.s0")) {
193+ session->createTimeseries(
194+ "root.test.d0.s0", TSDataType::INT64, TSEncoding::RLE, CompressionType::SNAPPY);
195+ }
196+
197+ session->close();
198+ std::cout << "IoTDB C++ session is ready." << std::endl;
199+ return 0;
200+ }
201+ ```
202+
203+ The examples in the package connect to ` 127.0.0.1:6667 ` with ` root ` / ` root `
204+ by default. Start IoTDB before running them.
205+
206+ ### Runtime deployment notes
207+
208+ - Linux release packages are built in the ` manylinux2014 ` container and require
209+ glibc 2.17 or newer.
210+ - Windows packages use the dynamic MSVC runtime (` /MD ` ). Install the Microsoft
211+ Visual C++ Redistributable matching your Visual Studio generation on target
212+ machines that do not already have it.
213+ - Put ` libiotdb_session.so ` , ` libiotdb_session.dylib ` , or ` iotdb_session.dll `
214+ next to your executable, or configure the platform library search path. On
215+ Linux, keep the ` libiotdb_session.so* ` symlink chain together when copying
216+ files manually.
217+
218+ ## Build the SDK from source
219+
23220The C++ client is built by a single top-level ` CMakeLists.txt ` in this
24221directory. The outer Maven POM is a thin wrapper that invokes CMake; you can
25222also build the client standalone with just ` cmake ` if you don't have Maven
26223available.
27224
28- ## Build layout at a glance
225+ ### Build layout at a glance
29226
30227```
31228iotdb-client/client-cpp/
@@ -55,7 +252,7 @@ During configure CMake will, in order:
552526 . ` cmake --install ` lays out the SDK under ` target/install/{include,lib} ` ,
56253 which Maven's assembly step packages into a zip.
57254
58- ## Build matrix
255+ ### Build matrix
59256
60257| Goal | Command |
61258| -------------------------------| --------------------------------------------------------------------------------------------------------|
@@ -309,6 +506,7 @@ A successful `mvn ... package` produces
309506
310507```
311508README.md
509+ README_zh.md
312510LICENSE
313511NOTICE
314512VERSION
@@ -335,37 +533,4 @@ examples/
335533Thrift is embedded inside ` iotdb_session ` on all platforms; it is not shipped
336534as a separate install artifact.
337535
338- ## Using the C++ client
339-
340- ``` cpp
341- #include " Session.h"
342- #include < memory>
343- #include < iostream>
344-
345- int main () {
346- auto session = std::make_shared<Session>("127.0.0.1", 6667, "root", "root");
347- session->open(false);
348- session->setStorageGroup("root.test01");
349- if (!session->checkTimeseriesExists("root.test01.d0.s0")) {
350- session->createTimeseries(
351- "root.test01.d0.s0",
352- TSDataType::INT64,
353- TSEncoding::RLE,
354- CompressionType::SNAPPY);
355- }
356- session->close();
357- }
358- ```
359-
360- Compile against the produced SDK:
361-
362- ```bash
363- clang++ -O2 user-cpp-code.cpp \
364- -I/path/to/sdk/include \
365- -L/path/to/sdk/lib \
366- -liotdb_session -lpthread \
367- -Wl,-rpath,/path/to/sdk/lib \
368- -std=c++11
369- ```
370-
371536For full API documentation see the [ C++ Native API guide] ( https://iotdb.apache.org/UserGuide/latest/API/Programming-Cpp-Native-API.html ) .
0 commit comments