1

I have installed the Mongo C Driver on ubuntu 16.04 using the command:

sudo apt-get install libmongoc-1.0-0


When I try to compile using cmake, I get the following errors:

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

It seems to me that the C driver installation has a problem, or could it be cmake? The cmake file I use is:

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}")


Is there some step I have forgotten? Ideas welcome.


Update
I found references to pkg-config and libmongoc-1.0.pc file in another post and checked this out:

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:~$

I checked the whole FS and the .pc file is not there. If indeed this is the problem, what process should create this and how do I fix this?

RR1
  • 333
  • 1
  • 6
  • 13

1 Answers1

5

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