RR1*_*RR1 1 mongo-c-driver ubuntu-16.04
我已经使用以下命令在 ubuntu 16.04 上安装了 Mongo C 驱动程序:
sudo apt-get install libmongoc-1.0-0
当我尝试使用 cmake 进行编译时,出现以下错误:
rolf@ubuntu2:~/src/test$ cmake .
-- The C compiler identification is GNU 5.4.0
-- The CXX compiler identification is GNU 5.4.0
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
CMake Error at CMakeLists.txt:4 (find_package):
By not providing "Findlibmongoc-1.0.cmake" in CMAKE_MODULE_PATH this
project has asked CMake to find a package configuration file provided by
"libmongoc-1.0", but CMake did not find one.
Could not find a package configuration file provided by "libmongoc-1.0"
(requested version 1.7) with any of the following names:
libmongoc-1.0Config.cmake
libmongoc-1.0-config.cmake
Add the installation prefix of "libmongoc-1.0" to CMAKE_PREFIX_PATH or set
"libmongoc-1.0_DIR" to a directory containing one of the above files. If
"libmongoc-1.0" provides a separate development package or SDK, be sure it
has been installed.
-- Configuring incomplete, errors occurred!
See also "/home/rolf/src/test/CMakeFiles/CMakeOutput.log".
rolf@ubuntu2:~/src/test$ apt list --installed
Run Code Online (Sandbox Code Playgroud)
我感觉是C驱动安装有问题,或者可能是cmake的问题?我使用的cmake文件是:
cmake_minimum_required(VERSION 6.5)
# Specify the minimum version you require.
find_package (libmongoc-1.0 1.7 REQUIRED)
message ("-- mongoc found version \"${MONGOC_VERSION}\"")
message ("-- mongoc include path \"${MONGOC_INCLUDE_DIRS}\"")
message ("-- mongoc libraries \"${MONGOC_LIBRARIES}\"")
# sample program
add_executable (error-example error-example.c)
target_include_directories (error-example PRIVATE "${MONGOC_INCLUDE_DIRS}")
target_link_libraries (error-example PRIVATE "${MONGOC_LIBRARIES}")
target_compile_definitions (error-example PRIVATE "${MONGOC_DEFINITIONS}")
Run Code Online (Sandbox Code Playgroud)
是不是有什么步骤我忘记了?欢迎提出想法。
更新
我在另一篇文章中找到了对 pkg-config 和 libmongoc-1.0.pc 文件的引用并检查了这一点:
rolf@lme-u1604:~$ pkg-config --cflags --libs libmongoc-1.0
Package libmongoc-1.0 was not found in the pkg-config search path.
Perhaps you should add the directory containing `libmongoc-1.0.pc'
to the PKG_CONFIG_PATH environment variable
No package 'libmongoc-1.0' found
rolf@lme-u1604:~$
Run Code Online (Sandbox Code Playgroud)
我检查了整个 FS,但 .pc 文件不存在。如果确实是这个问题,那么什么过程应该创建这个问题以及如何解决这个问题?
小智 5
至少对于 ubuntu 来说,安装方法并不完整。
您需要进一步安装:
sudo apt-get install libmongoc-dev
sudo apt-get install libbson-dev
sudo apt-get install libbson-1.0-0
Run Code Online (Sandbox Code Playgroud)
到目前为止,一切都很好。
如果您遵循他们给出的示例
尝试
#include <mongoc.h>
Run Code Online (Sandbox Code Playgroud)
代替:
#include <mongoc/mongoc.h>
Run Code Online (Sandbox Code Playgroud)
#
你的 cmake 应该如下所示
cmake_minimum_required(VERSION 3.13)
project(mongodb_c C)
set(CMAKE_C_STANDARD 11)
include_directories("/usr/include/libmongoc-1.0")
include_directories("/usr/include/libbson-1.0")
add_executable(mongodb_c main.c)
target_link_libraries(mongodb_c /usr/lib/x86_64-linux-gnu/libmongoc-1.0.so.0 /usr/lib/x86_64-linux-gnu/libbson-1.0.so.0)
Run Code Online (Sandbox Code Playgroud)
假设您将代码放入名为 main.c 的文件中
干杯,
马哈茂德
归档时间: |
|
查看次数: |
3103 次 |
最近记录: |