Clion mongodb依赖设置



我得到以下错误:

--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所说的编译了所需的库,所以我有库文件:我编译的文件

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

find_library无法找到请求的库。

当你将库安装到非默认目录时(根据截图,它是C:mongo-c-driverbin),你需要提示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,请参阅其使用的搜索算法文档

最新更新