MongoDB.live, free & fully virtual. June 9th - 10th. Register Now

Beginner C question - can't find mongoc.h anywhere

Hello,

I am (still) beginner with mongodb, and starting out on my first attempt at a trivial C-language experiment with mongoc driver and related libraries. I am working in Ubuntu 18.04 64-bit environment. MongoDB is installed locally (version 4.2.5) and has been working well so far (as a runtime package accessed with mongodb shell and related utilities).

My problem now is that I cannot find mongoc.h anywhere even after installing what I think are the required packages using apt:

libmongoc-1.0
libmongoc-dev
libbson-1.0

I do not wish (at this point) to use cmake or pkg-config. As my first step, I wish only to use #include <mongoc/mongoc.h> in my source file (which is trivial) and link libmongoc-1.0 on the gcc command line. Searches on stackexchange all tell me to use cmake or pkg-config (I am trying minimize the number of moving parts until I am confident that the required files are even installed.)

apt install tells me:
libmongoc-1.0-0 is already the newest version (1.9.2+dfsg-1build1).
libmongoc-dev is already the newest version (1.9.2+dfsg-1build1).
libbson-1.0-0 is already the newest version (1.9.2-1).

So far, I cannot complete gcc for a C program which has #include <mongoc/mongoc.h>, as that file is not found. I cannot find a file called mongoc.h anywhere in my local file system. I cannot find a directory called mongoc anywhere (I’d expect it to be in /usr somewhere.)

How can I proceed?

Thank you very much!

Dave

OK sorry burn the bandwidth - I found solution (but couldn’t immediately correct my post because of moderation lag.)

The include files were stored in /usr/include; the -I parameters to gcc were pointing to /usr/local/include. Probably caused by following two separate versioned sets of instructions (one to install the development files, one to do the compile/link.)

Once I got both to agree, I was able to compile/run the example from mongodb documentation.

Sorry again for the bandwidth!

Dave

A bit of additional detail for those who might find this. Specific issue is that the headers are located in a subdirectory of /usr/include. Specifically, the subdirectories are /usr/include/libbson-1.0 and /usr/include/libmongoc-1.0. If you choose not use pkg-config or CMake to build against the C Driver, you will need to ensure that your CFLAGS contains “`-I/usr/include/libbson-1.0 -I/usr/include/libmongoc-1.0” so that the headers can be found.

1 Like