Windows
注:我的根目录: D:\iotdb\iotdb (D:\iotdb>git clone https://github.com/apache/iotdb.git)
下载依赖
- 下载Maven:https://dlcdn.apache.org/maven/maven-3/3.8.5/binaries/apache-maven-3.8.5-bin.zip
- 解压后,加入系统环境变量path中,如: D:\download\apache-maven-3.8.5\bin
- 安装CMake: https://github.com/Kitware/CMake/releases/download/v3.23.1/cmake-3.23.1-windows-x86_64.msi
- 安装flex和bison: https://onboardcloud.dl.sourceforge.net/project/winflexbison/win_flex_bison-latest.zip
- 下载解压后: D:\download\win_flex_bison-latest,
- win_bison.exe重命名bison.exe, win_flex.exe 重命名flex.exe
- 加入系统环境变量path中,D:\download\win_flex_bison-latest
- 安装OpenSSL:http://slproweb.com/download/Win64OpenSSL-1_1_1o.msi
- 下载boost库: https://boostorg.jfrog.io/artifactory/main/release/1.79.0/source/boost_1_79_0.zip
- 解压 如:D:\download\boost_1_79_0\boost_1_79_0
编译
D:\iotdb>iotdb> mvn package -P compile-cpp -pl client-cpp,server,example/client-cpp-example -am -Dcmake.generator="Visual Studio 15 2017" -Dboost.include.dir="D:\download\boost_1_79_0\boost_1_79_0" -Dboost.library.dir="D:\download\boost_1_79_0\boost_1_79_0\stage\lib"
注: 上述编译client-cpp-example project 的时候会copy client-cpp 编译的静态库lib和头文件至 示例目录下:client-cpp-example\target\client
Code Block | ||||
---|---|---|---|---|
| ||||
拷贝c++客户端库是在这里做的:
D:\iotdb\iotdb\example\client-cpp-example\pom.xml
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>unpack-client</id>
<goals>
<goal>unpack</goal>
</goals>
<configuration>
<artifactItems>
<artifactItem>
<groupId>org.apache.iotdb</groupId>
<artifactId>client-cpp</artifactId>
<version>${project.version}</version>
<type>zip</type>
<classifier>cpp-${os.classifier}</classifier>
<overWrite>true</overWrite>
</artifactItem>
</artifactItems>
<outputDirectory>${project.build.directory}/client</outputDirectory>
</configuration>
</execution>
</executions>
</plugin> |
源:D:\iotdb\iotdb\client-cpp\target\client-cpp-0.13.1-SNAPSHOT-cpp-windows-x86_64
目标: D:\iotdb\iotdb\example\client-cpp-example\target\client
目录如下:
D:\IOTDB\IOTDB\CLIENT-CPP\TARGET\CLIENT-CPP-0.13.1-SNAPSHOT-CPP-WINDOWS-X86_64
├───include
│ └───thrift
│ ├───async
│ ├───concurrency
│ ├───processor
│ ├───protocol
│ ├───qt
│ ├───server
│ ├───transport
│ └───windows
└───lib
└───Release
VS2017 打开调试示例:
打开maven编译产生的 VS solution 文件: D:\iotdb\iotdb\example\client-cpp-example\target\SessionExample.sln
可以看到依赖cpp-client 的库在链接阶段被链接进来了:
VS2017-》选中project SessionExample-》右键点击属性-》Configuration Properties-》linker-》General-》Additional LibraryDirectories:
D:/iotdb/iotdb/example/client-cpp-example/target/../target/client/lib/Release
D:/iotdb/iotdb/example/client-cpp-example/target/../target/client/lib/Release/Release
D:/iotdb/iotdb/example/client-cpp-example/target/../target/client/lib
%(AdditionalLibraryDirectories)
用depends (https://www.dependencywalker.com/depends22_x64.zip)查看,没有特别的动态依赖:
可能遇到的问题
1.maven 编译无法编译thrift?
这个可能与公司内网的proxy需要认证有关系,pom中的wget goal 都可以直接手动下载放到对应的目录中:
1)compile-tools\thrift
a) 下载thrift 并且解到: D:\iotdb\iotdb\compile-tools\thrift\target\thrift-0.14.1
b) 下载cmake并且解压到:D:\iotdb\iotdb\compile-tools\thrift\target\cmake-3.17.3-win64-x64
注: 具体版本和url 可以在pom.xml 查看。
Code Block | ||||
---|---|---|---|---|
| ||||
D:\iotdb\iotdb\compile-tools\thrift\pom.xml
<plugin>
<groupId>com.googlecode.maven-download-plugin</groupId>
<artifactId>download-maven-plugin</artifactId>
<version>1.6.7</version>
<executions>
<!-- Download the CMake binary distribution for this platform. -->
<execution>
<id>get-cmake</id>
<phase>generate-sources</phase>
<goals>
<goal>wget</goal>
</goals>
<configuration>
<url>${cmake.url}</url>
<unpack>true</unpack>
<outputDirectory>${project.build.directory}</outputDirectory>
</configuration>
</execution>
<!-- Download the sources for building the thrift compiler -->
<execution>
<id>get-thrift</id>
<phase>generate-sources</phase>
<goals>
<goal>wget</goal>
</goals>
<configuration>
<url>http://archive.apache.org/dist/thrift/${thrift.version}/thrift-${thrift.version}.tar.gz</url>
<unpack>true</unpack>
<outputDirectory>${project.build.directory}</outputDirectory>
</configuration>
</execution>
</executions>
</plugin> |
2) client-cpp
catch.hpp : https://github.com/catchorg/Catch2/releases/download/v2.13.0/catch.hpp
Code Block | ||||
---|---|---|---|---|
| ||||
D:\iotdb\iotdb\client-cpp\pom.xml
<plugin>
<groupId>com.googlecode.maven-download-plugin</groupId>
<artifactId>download-maven-plugin</artifactId>
<version>1.6.7</version>
<executions>
<!-- Download the Catch2 header file. -->
<execution>
<id>get-catch2</id>
<phase>generate-resources</phase>
<goals>
<goal>wget</goal>
</goals>
<configuration>
<url>${catch2.url}</url>
<unpack>false</unpack>
<outputDirectory>${project.build.directory}/build/test/catch2</outputDirectory>
</configuration>
</execution>
</executions>
</plugin> |
2. VS2017 编译debug 配置版失败
可以用release配置,打开debug信息。 VS2017-》选中project SessionExample-》右键点击属性-》Configuration Properties-》linker-》Debugging-》Generate Debug Info-》选中Generate Debug Infomation/Debug
关闭优化:Configuration Properties-》C/C++-》Optimization-》选中Optimization Disabled(/Od)
Ubuntu-18.04
- sudo apt-get install automake bison flex g++ git libboost-all-dev libevent-dev libssl-dev libtool make pkg-config
- sudo apt-get install build-essential g++ python-dev autotools-dev libicu-dev libbz2-dev
- mvn package -P compile-cpp -pl example/client-cpp-example -am -DskipTest
- 可以用ldd或objdump 查看依赖库;
- ~/opensource/iotdb/example/client-cpp-example/target git:(rel/0.13) $ ldd SessionExample
linux-vdso.so.1 (0x00007ffea1c2c000)
libachk.so => /lib64/libachk.so (0x00007f0bab654000)
libiotdb_session.so => ~/opensource/iotdb/example/client-cpp-example/target/../target/client/lib/libiotdb_session.so (0x00007f0baae50000)
libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007f0baac31000)
libstdc++.so.6 => /lib/libstdc++.so.6 (0x00007f0baa8ae000)
libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007f0baa696000)
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f0baa2a5000)
libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007f0baa0a1000)
librt.so.1 => /lib/x86_64-linux-gnu/librt.so.1 (0x00007f0ba9e99000)
libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007f0ba9afb000)
/lib64/ld-linux-x86-64.so.2 (0x00007f0bab534000) - ~/opensource/iotdb/example/client-cpp-example/target git:(rel/0.13) $ objdump -p SessionExample | grep NEEDED
NEEDED libiotdb_session.so
NEEDED libpthread.so.0
NEEDED libstdc++.so.6
NEEDED libgcc_s.so.1
NEEDED libc.so.6
- ~/opensource/iotdb/example/client-cpp-example/target git:(rel/0.13) $ ldd SessionExample
注: 在linux中使用的是c++ client 动态链接库: libiotdb_session.so
如上所示 依赖库文件可以在ldd列出的对应目录中查找 (ls -lrt /lib/x86_64-linux-gnu)
如果目录不同可以用find命令查找一下: 如查找库: libpthread
> find / -name "libpthread*" -type f 2>/dev/null
可以查看一下:
➜ /lib/x86_64-linux-gnu $ ls -lrt | grep libpt
-rwxr-xr-x 1 root root 142K Jan 24 20:53 libpthread-2.27.so
lrwxrwxrwx 1 root root 18 Jan 24 20:53 libpthread.so.0 -> libpthread-2.27.so