2019-11-13 11:43:23 +08:00
|
|
|
### Build C++ SDK
|
2019-11-12 19:14:20 +08:00
|
|
|
|
2019-12-20 14:08:45 +08:00
|
|
|
The C++ SDK source code is under milvus/sdk.
|
|
|
|
If you want to build sdk project, follow below steps:
|
2019-11-12 19:14:20 +08:00
|
|
|
```shell
|
2019-12-20 14:08:45 +08:00
|
|
|
# build project
|
|
|
|
$ cd [Milvus root path]/sdk
|
|
|
|
$ ./build.sh
|
2019-11-12 19:14:20 +08:00
|
|
|
```
|
|
|
|
|
|
|
|
### Try C++ example
|
|
|
|
|
2019-11-13 11:43:23 +08:00
|
|
|
Firstly, you need to start a Milvus server.
|
|
|
|
If you've already built the entire milvus project, just start Milvus server with the following command:
|
2019-11-12 19:14:20 +08:00
|
|
|
```shell
|
|
|
|
# start milvus server
|
|
|
|
$ cd [Milvus root path]/core
|
|
|
|
$ ./start_server.sh
|
|
|
|
```
|
2019-11-13 11:43:23 +08:00
|
|
|
You can also use Docker to start Milvus server:
|
2019-11-12 19:14:20 +08:00
|
|
|
```shell
|
|
|
|
# pull milvus docker image and start milvus server
|
|
|
|
$ docker pull milvusdb/milvus:latest
|
|
|
|
$ docker run --runtime=nvidia -p 19530:19530 -d milvusdb/milvus:latest
|
|
|
|
```
|
|
|
|
|
2019-11-12 19:45:21 +08:00
|
|
|
Run C++ example:
|
2019-11-12 19:14:20 +08:00
|
|
|
|
|
|
|
```shell
|
|
|
|
# run milvus C++ example
|
2019-12-20 14:08:45 +08:00
|
|
|
$ cd [Milvus root path]/sdk/cmake_build/examples/simple
|
2019-11-12 19:14:20 +08:00
|
|
|
$ ./sdk_simple
|
|
|
|
```
|
|
|
|
|
|
|
|
### Make your own C++ client project
|
|
|
|
|
2019-11-13 11:43:23 +08:00
|
|
|
Create a folder for the project, and copy C++ SDK header and library files into it.
|
2019-11-12 19:14:20 +08:00
|
|
|
```shell
|
|
|
|
# create project folder
|
|
|
|
$ mkdir MyMilvusClient
|
|
|
|
$ cd MyMilvusClient
|
|
|
|
|
|
|
|
# copy necessary files
|
2019-12-20 14:08:45 +08:00
|
|
|
$ cp [Milvus root path]/sdk/cmake_build/libmilvus_sdk.so .
|
|
|
|
$ cp [Milvus root path]/sdk/include/MilvusApi.h .
|
|
|
|
$ cp [Milvus root path]/sdk/include/Status.h .
|
2019-11-12 19:14:20 +08:00
|
|
|
```
|
|
|
|
|
2019-11-13 11:43:23 +08:00
|
|
|
Create file main.cpp in the project folder, and copy the following code into it:
|
2019-11-12 19:14:20 +08:00
|
|
|
```shell
|
|
|
|
#include "./MilvusApi.h"
|
|
|
|
#include "./Status.h"
|
|
|
|
|
|
|
|
int main() {
|
|
|
|
// connect to milvus server
|
|
|
|
std::shared_ptr<milvus::Connection> conn = milvus::Connection::Create();
|
|
|
|
milvus::ConnectParam param = {"127.0.0.1", "19530"};
|
|
|
|
conn->Connect(param);
|
|
|
|
|
|
|
|
// put your client code here
|
|
|
|
|
|
|
|
milvus::Connection::Destroy(conn);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
```
|
|
|
|
|
2019-11-13 11:43:23 +08:00
|
|
|
Create file CMakeList.txt in the project folder, and copy the following code into it:
|
2019-11-12 19:14:20 +08:00
|
|
|
```shell
|
|
|
|
cmake_minimum_required(VERSION 3.14)
|
|
|
|
project(test)
|
|
|
|
set(CMAKE_CXX_STANDARD 14)
|
|
|
|
|
|
|
|
add_executable(milvus_client main.cpp)
|
|
|
|
target_link_libraries(milvus_client
|
|
|
|
${PROJECT_SOURCE_DIR}/libmilvus_sdk.so)
|
|
|
|
```
|
|
|
|
|
2019-11-12 19:45:21 +08:00
|
|
|
Now there are 5 files in your project:
|
|
|
|
```shell
|
|
|
|
MyMilvusClient
|
|
|
|
|-CMakeList.txt
|
|
|
|
|-main.cpp
|
|
|
|
|-libmilvus_sdk.so
|
|
|
|
|-MilvusApi.h
|
|
|
|
|-Status.h
|
|
|
|
```
|
|
|
|
|
|
|
|
Build the project:
|
2019-11-12 19:14:20 +08:00
|
|
|
```shell
|
|
|
|
$ mkdir cmake_build
|
|
|
|
$ cd cmake_build
|
|
|
|
$ cmake ..
|
|
|
|
$ make
|
|
|
|
```
|
|
|
|
|
|
|
|
Run your client program:
|
|
|
|
```shell
|
|
|
|
$ ./milvus_client
|
|
|
|
```
|