MAC
Install Bison:
Use the following brew command to install the Bison version:
brew install bison
Install Boost: Make sure to install the latest version of Boost.
brew install boost
Check OpenSSL: Make sure the OpenSSL library is installed. The default OpenSSL header file path is “/usr/local/opt/openssl/include”.
If you encounter errors related to OpenSSL not being found during compilation, try adding -Dopenssl.include.dir="".
Ubuntu 16.04+ or Other Debian-based Systems
Use the following commands to install dependencies:
sudo apt-get update sudo apt-get install gcc g++ bison flex libboost-all-dev libssl-dev
CentOS 7.7+/Fedora/Rocky Linux or Other Red Hat-based Systems
Use the yum command to install dependencies:
sudo yum update sudo yum install gcc gcc-c++ boost-devel bison flex openssl-devel
Windows
Set Up the Build Environment
Download and Install Flex, Bison
Install Boost Library
bootstrap.bat and b2.exe in sequence.C:\Program Files (x86)\boost_1_78_0.Install OpenSSL
Clone the source code from git:
git clone https://github.com/apache/iotdb.git
The default main branch is the master branch. If you want to use a specific release version, switch to that branch (e.g., version 1.3.2):
git checkout rc/1.3.2
Run Maven to compile in the IoTDB root directory:
Mac or Linux with glibc version >= 2.32
./mvnw clean package -pl example/client-cpp-example -am -DskipTests -P with-cpp
Linux with glibc version >= 2.31
./mvnw clean package -pl example/client-cpp-example -am -DskipTests -P with-cpp -Diotdb-tools-thrift.version=0.14.1.1-old-glibc-SNAPSHOT
Linux with glibc version >= 2.17
./mvnw clean package -pl example/client-cpp-example -am -DskipTests -P with-cpp -Diotdb-tools-thrift.version=0.14.1.1-glibc223-SNAPSHOT
Windows using Visual Studio 2022
.\mvnw.cmd clean package -pl example/client-cpp-example -am -DskipTests -P with-cpp
Windows using Visual Studio 2019
.\mvnw.cmd clean package -pl example/client-cpp-example -am -DskipTests -P with-cpp -Dcmake.generator="Visual Studio 16 2019" -Diotdb-tools-thrift.version=0.14.1.1-msvc142-SNAPSHOT
-DboostIncludeDir="C:\Program Files (x86)\boost_1_78_0" -DboostLibraryDir="C:\Program Files (x86)\boost_1_78_0\stage\lib".After successful compilation, the packaged library files will be located in iotdb-client/client-cpp/target, and you can find the compiled example program under example/client-cpp-example/target.
Q: What are the requirements for the environment on Linux?
A:
./mvnw clean install../mvnw clean package -pl example/client-cpp-example -am -DskipTests -P with-cpp.Q: How to resolve the undefined reference to '_libc_single_thread' error during Linux compilation?
A:
-Diotdb-tools-thrift.version=0.14.1.1-glibc223-SNAPSHOT or -Diotdb-tools-thrift.version=0.14.1.1-old-glibc-SNAPSHOT to the Maven compile command.Q: What if I need to compile using Visual Studio 2017 or earlier on Windows?
A:
.\mvnw.cmd clean install..\mvnw.cmd clean package -pl example/client-cpp-example -am -DskipTests -P with-cpp -Dcmake.generator="Visual Studio 15 2017".All operations in the C++ client are performed through the TableSession class. Below are the method descriptions defined in the TableSession interface.
insert(Tablet& tablet, bool sorted = false): Inserts a Tablet object containing time series data into the database. The sorted parameter indicates whether the rows in the tablet are already sorted by time.executeNonQueryStatement(string& sql): Executes non-query SQL statements, such as DDL (Data Definition Language) or DML (Data Manipulation Language) commands.executeQueryStatement(string& sql): Executes query SQL statements and returns a SessionDataSet object containing the query results. The optional timeoutInMs parameter indicates the timeout return time.open(bool enableRPCCompression = false): Opens the connection and determines whether to enable RPC compression (client state must match server state, disabled by default).close(): Closes the connection.class TableSession { private: Session* session; public: TableSession(Session* session) { this->session = session; } void insert(Tablet& tablet, bool sorted = false); void executeNonQueryStatement(const std::string& sql); unique_ptr<SessionDataSet> executeQueryStatement(const std::string& sql); unique_ptr<SessionDataSet> executeQueryStatement(const std::string& sql, int64_t timeoutInMs); string getDatabase(); //Get the currently selected database, can be replaced by executeNonQueryStatement void open(bool enableRPCCompression = false); void close(); };
The TableSessionBuilder class is a builder used to configure and create instances of the TableSession class. Through it, you can conveniently set connection parameters, query parameters, and other settings when creating instances.
//Set connection IP, port, username, password //The order of settings is arbitrary, just ensure build() is called last, the created instance is connected by default through open() session = (new TableSessionBuilder()) ->host("127.0.0.1") ->rpcPort(6667) ->username("root") ->password("root") ->build();
| Parameter Name | Description | Default Value |
|---|---|---|
| host | Set the connected node IP | “127.0.0.1” (“localhost”) |
| rpcPort | Set the connected node port | 6667 |
| username | Set the connection username | “root” |
| password | Set the connection password | “root” |
| zoneId | Set the ZoneId related to timezone | "" |
| fetchSize | Set the query result fetch size | 10000 |
| database | Set the target database name | "" |
The sample code of using these interfaces is in:
example/client-cpp-example/src/TableSessionExample.cpp: TableSessionExampleIf the compilation finishes successfully, the example project will be placed under example/client-cpp-example/target
If errors occur when compiling thrift source code, try to downgrade your xcode-commandline from 12 to 11.5
When Building Thrift and downloading packages via “wget”, a possible annoying issue may occur with error message looks like:
Failed to delete cached file C:\Users\Administrator\.m2\repository\.cache\download-maven-plugin\index.ser
Possible fixes: