包括2020年的mongocxx

时间:2020-06-02 20:30:07

标签: mongodb

当我尝试使用

包含mongo时
find_package(libmongocxx REQUIRED)
find_package(libbsoncxx REQUIRED)

我所得到的是>

  This CMake target is deprecated.  Use 'mongo::mongocxx_shared' instead.
  Consult the example projects for further details.
  This CMake target is deprecated.  Use 'mongo::bsoncxx_shared' instead.
  Consult the example projects for further details.

我应该如何正确包含mongo?我有点迷路了。

笔记,我可以包括它,它可以“起作用”,但是我想“适当地”做到。

1 个答案:

答案 0 :(得分:2)

是的,您正在使用旧指令。现在您可以使用类似这样的东西:

cmake_minimum_required(VERSION 3.16)
project(mongo_test)

set(CMAKE_CXX_STANDARD 17)

add_executable(mongo_test main.cpp)

find_package(mongocxx REQUIRED)
find_package(bsoncxx REQUIRED)
include_directories(${LIBMONGOCXX_INCLUDE_DIR})
include_directories(${LIBBSONCXX_INCLUDE_DIR})

target_link_libraries(${PROJECT_NAME} PRIVATE mongo::bsoncxx_shared)

target_link_libraries(${PROJECT_NAME} PRIVATE mongo::mongocxx_shared)

在Fedora 32(gcc 10.1,cmake版本3.16)上运行