gpt4 book ai didi

c++ - Clion mongodb 依赖设置

转载 作者:可可西里 更新时间:2023-11-01 10:03:04 26 4
gpt4 key购买 nike

我收到以下错误:

--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关于它使用的搜索算法。

关于c++ - Clion mongodb 依赖设置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38109060/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com