1

我已经使用以下命令在 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

在我看来是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}")


有没有我忘记的步骤?欢迎提出想法。


更新
我在另一篇文章中找到了对 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:~$

我检查了整个 FS 并且 .pc 文件不存在。如果确实是这个问题,应该由什么过程来创建这个问题,我该如何解决这个问题?

4

1 回答 1

4

The how-to installation is not complete, at least for ubuntu.

you need to further install:

  sudo  apt-get install libmongoc-dev
  sudo  apt-get install libbson-dev
  sudo  apt-get install libbson-1.0-0

So far so good.

If you are following the example they gave

try

      #include <mongoc.h>

instead of:

      #include <mongoc/mongoc.h>
#

your cmake should look like the following

 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)

assuming you put your code in a file named main.c

cheers,

Mahmoud

于 2019-01-13T16:09:17.500 回答