Clion mongodb 依赖设置

Clion mongodb dependency setup

我收到以下错误:

--Configuring incomplete, errors occurred!
CMake Error: The following variables are used in this project, but they are set to NOTFOUND.
See also "C:/Users/GyuriX/.CLion2016.1/system/cmake/generated/Projects-33418280/33418280/Debug/CMakeFiles/CMakeOutput.log".
Please set them or make sure they are set and tested correctly in the CMake files:
BSON_LIBRARY
    linked by target "Projects" in directory D:/DEV/C/Projects
MONGODB_LIBRARY
    linked by target "Projects" in directory D:/DEV/C/Projects

Makefile:443: recipe for target 'cmake_check_build_system' failed
mingw32-make.exe: *** [cmake_check_build_system] Error 1

当我尝试使用以下 CMakeLists.txt:

编译一个简单的 Hello World 程序时
cmake_minimum_required(VERSION 2.8)
project(Projects)

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
set(SOURCE_FILES main.cpp)

include_directories(C:/mongo-c-driver/lib)

find_library(MONGODB_LIBRARY mongoc-1.0)
find_library(BSON_LIBRARY bson-1.0)

add_executable(Projects ${SOURCE_FILES})
target_link_libraries(Projects ${MONGODB_LIBRARY} ${BSON_LIBRARY})

我已经根据 mongodb wiki 所说的编译了所需的库,所以我有库文件: The files I have compiled

所以问题是我做错了什么,我应该怎么做才能在 CLion 中使用 mongodb。

错误消息表示 find_library 找不到请求的库。

当您将库安装到非默认目录(根据屏幕截图,它是 C:\mongo-c-driver\bin)时,您需要提示 find_library() 它应该搜索的位置。

一种可能的方法是设置 CMake 变量 CMAKE_LIBRARY_PATH:

set(CMAKE_LIBRARY_PATH "C:\mongo-c-driver\bin")
# Now find_library should be able to find libraries
find_library(MONGODB_LIBRARY mongoc-1.0)
find_library(BSON_LIBRARY bson-1.0)

还有其他提示 find_library 的方法,请参阅 its documentation 关于它使用的搜索算法。