milvus/sdk/README.md

112 lines
2.3 KiB
Markdown
Raw Normal View History

# Milvus C++ SDK
### Get C++ SDK
If you compile Milvus from source, C++ SDK is already in `[Milvus root path]/sdk`. If you install Milvus from Docker images, you need to download the whole `sdk` folder to your host.
### Requirements
CMake 3.14 or higher
2019-11-13 11:43:23 +08:00
### Build C++ SDK
2019-11-12 19:14:20 +08:00
You must build the C++ SDK before using it:
2019-11-12 19:14:20 +08:00
```shell
# build C++ SDK
$ cd [Milvus root path]/sdk
$ ./build.sh
2019-11-12 19:14:20 +08:00
```
### Try C++ example
You must have a running Milvus server to try the C++ example. Refer to [Milvus Documentation](https://milvus.io/docs/guides/get_started/install_milvus/install_milvus.md) to learn how to install and run a Milvus server.
2019-11-12 19:14:20 +08:00
2019-11-12 19:45:21 +08:00
Run C++ example:
2019-11-12 19:14:20 +08:00
```shell
# run Milvus C++ example
$ cd [Milvus root path]/sdk/cmake_build/examples/simple
2019-11-12 19:14:20 +08:00
$ ./sdk_simple
```
2019-11-12 19:14:20 +08:00
### Create your own C++ client project
2019-11-12 19:14:20 +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
$ cp [Milvus root path]/sdk/cmake_build/libmilvus_sdk.so .
$ cp -r [Milvus root path]/sdk/include .
2019-11-12 19:14:20 +08:00
```
- Create file `main.cpp` in the project folder, and copy the following code into it:
```c++
#include "./include/MilvusApi.h"
#include "./include/Status.h"
2019-11-12 19:14:20 +08:00
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;
}
```
- Create file `CMakeLists.txt` in the project folder, and copy the following code into it:
```bash
2019-11-12 19:14:20 +08:00
cmake_minimum_required(VERSION 3.14)
project(test)
set(CMAKE_CXX_STANDARD 17)
2019-11-12 19:14:20 +08:00
add_executable(milvus_client main.cpp)
target_link_libraries(milvus_client
${PROJECT_SOURCE_DIR}/libmilvus_sdk.so
pthread)
2019-11-12 19:14:20 +08:00
```
- Now the file structure of your project:
2019-11-12 19:45:21 +08:00
```shell
MyMilvusClient
|-CMakeLists.txt
2019-11-12 19:45:21 +08:00
|-main.cpp
|-libmilvus_sdk.so
|-include
|-MilvusApi.h
|-Status.h
|-......
```
2019-11-12 19:45:21 +08:00
- Build the project:
2019-11-12 19:14:20 +08:00
```shell
$ mkdir cmake_build
$ cd cmake_build
$ cmake ..
$ make
```
- Run your client program:
2019-11-12 19:14:20 +08:00
```shell
$ ./milvus_client
```
### Troubleshooting
- compile error "cannot find -lz"
```shell
$ apt-get install zlib1g-dev.
```