diff --git a/CHANGELOG.md b/CHANGELOG.md index 1087c1b0e0f54ab281fbbd55228180c1593245cd..3f78e7219257e592dab2c1cc33579779985054a0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,7 +12,8 @@ Please mark all change in change log and use the ticket from JIRA. - \#204 - improve grpc performance in search - \#207 - Add more unittest for config set/get - \#208 - optimize unittest to support run single test more easily -- \#284 - Change C++ SDK to shread library +- \#284 - Change C++ SDK to shared library +- \#260 - C++ SDK README ## Task diff --git a/core/src/sdk/README.md b/core/src/sdk/README.md new file mode 100644 index 0000000000000000000000000000000000000000..0f4e20d0e76dd3073d16eeb03aeb2d792c9ece56 --- /dev/null +++ b/core/src/sdk/README.md @@ -0,0 +1,103 @@ +### Build C++ SDK + +The C++ SDK source code is under milvus/core/src/sdk. Build entire milvus project will also build the C++ SDK project. +If you don't want to build the entire milvus project, follow below steps: +```shell + # generate make files + $ cd [Milvus root path]/core + $ ./build.sh -l + + # build C++ SDK project + $ cd [Milvus root path]/core/cmake_build + $ make -C src/sdk +``` + +### Try C++ example + +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: +```shell + # start milvus server + $ cd [Milvus root path]/core + $ ./start_server.sh +``` +You can also use Docker to start Milvus server: +```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 +``` + +Run C++ example: + +```shell + # run milvus C++ example + $ cd [Milvus root path]/core/cmake_build/src/sdk/examples/simple + $ ./sdk_simple +``` + +### Make your own C++ client project + +Create a folder for the project, and copy C++ SDK header and library files into it. +```shell + # create project folder + $ mkdir MyMilvusClient + $ cd MyMilvusClient + + # copy necessary files + $ cp [Milvus root path]/core/cmake_build/src/sdk/libmilvus_sdk.so . + $ cp [Milvus root path]/core/src/sdk/include/MilvusApi.h . + $ cp [Milvus root path]/core/src/sdk/include/Status.h . +``` + +Create file main.cpp in the project folder, and copy the following code into it: +```shell +#include "./MilvusApi.h" +#include "./Status.h" + +int main() { + // connect to milvus server + std::shared_ptr 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 CMakeList.txt in the project folder, and copy the following code into it: +```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) +``` + +Now there are 5 files in your project: +```shell +MyMilvusClient + |-CMakeList.txt + |-main.cpp + |-libmilvus_sdk.so + |-MilvusApi.h + |-Status.h + ``` + +Build the project: +```shell + $ mkdir cmake_build + $ cd cmake_build + $ cmake .. + $ make +``` + +Run your client program: +```shell + $ ./milvus_client +``` \ No newline at end of file