Skip to content

Commit 7ca4eae

Browse files
author
Jinzhi Chen
committed
Merge branch 'release130.21' into release130
2 parents 98147ed + f5bdcec commit 7ca4eae

File tree

3 files changed

+81
-0
lines changed

3 files changed

+81
-0
lines changed

demo/CMakeLists.txt

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
cmake_minimum_required(VERSION 3.4.1)
2+
set(ProjectName apiDemo)
3+
4+
project(${ProjectName})
5+
6+
set(SRC_LIST
7+
${CMAKE_CURRENT_SOURCE_DIR}/src/main.cpp
8+
)
9+
if(UNIX)
10+
add_compile_options(-std=c++11 -DLINUX -Wall -O0 -g -fPIC -Wl,-rpath,${CMAKE_CURRENT_SOURCE_DIR}:${CMAKE_CURRENT_SOURCE_DIR}/lib)
11+
elseif(WIN32)
12+
if(MSVC)
13+
add_compile_options(-DWINDOWS -DNOMINMAX -D_DEBUG)
14+
include_directories(
15+
${SSL_LIBS}/include64
16+
)
17+
elseif(MINGW)
18+
add_compile_options(-std=c++11 -DWINDOWS -Wall -O0 -g -fPIC -Wl,-rpath,${CMAKE_CURRENT_SOURCE_DIR}:${CMAKE_CURRENT_SOURCE_DIR}/lib)
19+
endif()
20+
endif()
21+
22+
include_directories(
23+
${CMAKE_CURRENT_SOURCE_DIR}/../include
24+
)
25+
link_directories(
26+
${CMAKE_CURRENT_SOURCE_DIR}/lib/
27+
)
28+
add_executable(${ProjectName} ${SRC_LIST})
29+
30+
if(UNIX)
31+
target_link_libraries(${ProjectName}
32+
DolphinDBAPI
33+
rt
34+
pthread
35+
)
36+
elseif(WIN32)
37+
if(MSVC)
38+
target_link_libraries(${ProjectName}
39+
DolphinDBAPI
40+
)
41+
elseif(MINGW)
42+
target_link_libraries(${ProjectName}
43+
DolphinDBAPI
44+
pthread
45+
)
46+
endif()
47+
endif()
48+
49+
50+
set(EXECUTABLE_OUTPUT_PATH ${CMAKE_CURRENT_SOURCE_DIR}/bin/)

demo/README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
1. 解压demo.zip到src目录下
2+
2. 将编译好的C++ API动态库拷贝到demo/lib目录下
3+
3. 执行下面的命令,以Visual Studio 2022为例,其中用SSL_LIBS参数指定openssl库位置
4+
cd api-cplusplus/demo
5+
mkdir build && cd build
6+
cmake .. -G "Visual Studio 17 2022" -A x64 -DSSL_LIBS=D:/openssl-1.0.2l-vs2017
7+
cmake --build .
8+
4. 生成的可执行文件apiDemo.exe在demo\bin\Debug目录下
9+
5. 将所依赖的动态库(DolphinDBAPI.dll libeay32MD.dll ssleay32MD.dll)拷贝到该目录下即可执行
10+
6. 这个demo同样支持mingw以及Linux,只是cmake语句略有不同

demo/src/main.cpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#include "DolphinDB.h"
2+
#include "Util.h"
3+
#include <iostream>
4+
#include <string>
5+
using namespace dolphindb;
6+
using namespace std;
7+
8+
int main(int argc, char* argv[]) {
9+
10+
DBConnection conn;
11+
bool ret = conn.connect("192.168.0.23", 8848);
12+
if (!ret) {
13+
cout << "Failed to connect to the server" << endl;
14+
return 0;
15+
}
16+
ConstantSP vector = conn.run("`IBM`GOOG`YHOO");
17+
int size = vector->rows();
18+
for (int i = 0; i < size; ++i)
19+
cout << vector->getString(i) << endl;
20+
return 0;
21+
}

0 commit comments

Comments
 (0)