Skip to content

Latest commit

 

History

History

README.md

C++ Client

支持 MacOS、Linux、Windows

Install third party

DuckDB

DuckDB Installation

MacOS下载的文件中有个libduckdb.dylib,将它拷贝到/usr/local/lib文件夹下

Linux下载的文件中有个libduckdb.so和libduckdb_static.a,将它拷贝到/usr/local/lib文件夹下

Windows下载的文件中有个duckdb.dll和duckdb.lib,将它们拷贝到C:\Windows\System32文件夹下

MongoDB

  • c driver github下载源码安装

    cxx依赖c driver,要先安装c driver。从源码安装:

    # 安装 libbson
    cmake -S . -B ./_build -D ENABLE_EXTRA_ALIGNMENT=OFF -D ENABLE_AUTOMATIC_INIT_AND_CLEANUP=OFF -D CMAKE_BUILD_TYPE=RelWithDebInfo -D ENABLE_MONGOC=OFF 
    cmake --build ./_build --config RelWithDebInfo --parallel
    # for MacOS/Linux
    cmake --install "./_build" --prefix "/usr/local" --config RelWithDebInfo
    # for Windows. 它会安装在C:\Program Files (x86)\mongo-c-driver
    cmake --install "./_build" --config RelWithDebInfo
    
    # 安装 libmongoc
    cmake -D ENABLE_MONGOC=ON ./_build
    cmake --build ./_build --config RelWithDebInfo --parallel
    # for MacOS/Linux
    cmake --install "./_build" --prefix "/usr/local" --config RelWithDebInfo
    # for Windows. 它会安装在C:\Program Files (x86)\mongo-c-driver
    cmake --install "./_build" --config RelWithDebInfo
  • cxx driver github下载安装

    • MacOS/Linux 从源码安装:
    cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_CXX_STANDARD=17 -DBUILD_VERSION="4.0.0"
    cmake --build .
    sudo cmake --build . --target install
    • Windows 从源码安装:

    参数 -G "Visual Studio <version> <year>" 填写自己的版本和年份

    <version>: Your Visual Studio version number

    <year>: The year corresponding to your Visual Studio version

    # CMAKE_INSTALL_PREFIX 要设置成刚才安装c driver的路径
    cmake.exe -G "Visual Studio 17 2022" -A "x64" -DCMAKE_CXX_STANDARD=17 -DCMAKE_PREFIX_PATH=C:\"Program Files (x86)"\mongo-c-driver -DBUILD_VERSION="4.1.1"
    cmake --build . --config RelWithDebInfo
    cmake --build . --target install --config RelWithDebInfo

    如果要安装DEBUG版本,将RelWithDebInfo改为DEBUG。如果在调试Debug模式下开发,必须安装Debug版本,否则会发生意想不到的Bug。

其他库

都以静态库的形式安装

  • fmt

    cmake -S . -B build -DCMAKE_BUILD_TYPE=Release -DCMAKE_POSITION_INDEPENDENT_CODE=TRUE 
    cmake --build ./build
    sudo cmake --build ./build --target install
    
    # or windows
    cmake -S . -B build -DCMAKE_POSITION_INDEPENDENT_CODE=TRUE
    cmake --build ./build --config RelWithDebInfo --parallel
    cmake --build ./build --target install --config RelWithDebInfo
  • yaml-cpp

    基本同上

    在Windows下find_packages报错:找不到yaml-cpp-config.cmake。需要将C:\Program Files (x86)\YAML_CPP路径改成C:\Program Files (x86)\YAML-CPP

Install

支持编译选项 -DBUILD_DUCKDB=0 禁止编译和安装duckdb相关的库

MacOS/Linux

cmake -S . -B ./build -DCMAKE_BUILD_TYPE=Release
cmake --build ./build
sudo cmake --build ./build --target install

Windows

在Visual Studio中调试:修改CMakePresets.json中的configurePresets > windows-base > CMAKE_PREFIX_PATH。这个是前面安装mongo c/cxx driver的路径,告诉CMake去哪个目录查找MongoDB的库文件。

一般cmake默认都安装在C:\Program Files (x86)\目录下,find_package()也会默认去该目录下查找。比如find_package(mongocxx),会去目录C:\Program Files (x86)\[mongocxx]\lib\cmake\[mongocxx]下查找mongocxx-config.cmake文件,只有前者[]文件夹名和后者[]内的文件夹名相同时,才能找到,否者就要通过指定CMAKE_PREFIX_PATH 告诉cmake从哪里查找。

CMAKE_PREFIX_PATH支持传入多个目录,以;隔开。

命令行安装:CMAKE_PREFIX_PATH 改成自己的目录。

cmake -S . -B ./build -G "Visual Studio 17 2022"  -DCMAKE_PREFIX_PATH="C:\Program Files\MONGO_CXX_DRIVER;C:\Program Files (x86)\mongo-c-driver"
cmake --build ./build --config RelWithDebInfo --parallel
cmake --build ./build --target install --config RelWithDebInfo

如果要安装Debug版本,将RelWithDebInfo换成Debug即可。

在其他项目作为依赖库使用

在其他项目的CMakeLists.txt中添加

find_package(quantdata REQUIRED)
target_link_libraries(YOUR_LIB quantdata::xxxx)

Test

# 添加 -V 打印所有输出
ctest -T test --test-dir out/build/linux-debug --output-on-failure