在cmake c ++项目中使用mongodb cxx驱动程序

pad*_*_89 4 c++ cmake mongodb c++11 mongodb-c

我是cmake的新手,我想使用c ++和最新的mongodb cxx驱动程序连接到mongodb.我设法编译并安装驱动程序,但现在我坚持在我的cmake项目中使用它.

我使用默认设置安装了mongodb驱动程序,因此它位于/ usr/local/lib/include/mongocxx/v_noabi/mongocxx下.

在我的cmake文件中,我管理以解决包含:

include_directories(/ usr/local/lib/include/mongocxx/v_noabi/usr/local/lib/include/bsoncxx/v_noabi)

但我不知道如何将驱动程序库链接到我的可执行文件.有人可以帮帮我吗?

小智 11

我已经完成了链接mongocxx驱动程序文档和使用CMake'find_package'链接的所有内容:

find_package(libmongocxx REQUIRED)
find_package(libbsoncxx REQUIRED)
include_directories(${LIBMONGOCXX_INCLUDE_DIR})
include_directories(${LIBBSONCXX_INCLUDE_DIR})
include_directories("/usr/local/include/mongocxx/v_noabi")
include_directories("/usr/local/include/bsoncxx/v_noabi")
include_directories("/usr/local/include/libmongoc-1.0")
include_directories("/usr/local/include/libbson-1.0")
include_directories("/usr/local/lib")

add_executable(YOUR_PROJECT ${SOURCE_FILES})

target_link_libraries(YOUR_PROJECT ${LIBMONGOCXX_LIBRARIES})
target_link_libraries(YOUR_PROJECT ${LIBBSONCXX_LIBRARIES})
Run Code Online (Sandbox Code Playgroud)

  • 我的意思是LIBBSONCXX_INCLUDE_DIR vs LIBBSONCXX_INCLUDE_DIR [S] (2认同)
  • 实际上,我在include_directories($ {LIBMONGOCXX_INCLUDE_DIRS})末尾使用包含目录变量和“ S” (2认同)

acm*_*acm 3

你不需要那样做。您可以而且应该通过 CMake 的find_packagepkg_check_modules子系统找到 C++11 驱动程序。C++11 驱动程序支持两者。