Attempt 2:
However, it does work if I specify the include directories manually
`
# CMakeLists.txt
include_directories(/usr/include/libmongoc-1.0)
include_directories(/usr/include/libbson-1.0)```
add_executable (hello_mongoc hello_mongoc.c)
target_link_libraries(hello_mongoc PUBLIC mongoc-1.0 bson-1.0)
Any insight?
Also, I cannot write mulitiple ticks and the code-formatting button only generates single ticks for some reason.
The #1 approach with CMake’s find_package should work. You just need to set the CMAKE_PREFIX_PATH variable to point to the directory where the C driver (libmongoc) is installed.
Adding include directories manually is discouraged since the C Driver installation already supplies CMake config-file package.
I apologize as I forgot to mention I receive this error even when using the manually included directories.
help_mongo.c:1:10: fatal error: mongoc/mongoc.h: No such file or directory
#include <mongoc/mongoc.h>
^~~~~~~~~~~~~~~~~
compilation terminated.
Although it “works” if I use #include <mongoc.h> but then I get a bunch of undefined reference errors. Even if its use is discouraged, we should still get the same intended result as the CMake route. Is it possible I’m using the wrong version? These are the packages included on my yum list installed:
The version string 1.3.6-1.el7 includes “el7” which means that the package came from the EPEL7 repo. Can you switch to EPEL8 repo? That has more recent 1.24.3 version
OR
You can build from source - that should get you the latest version (1.26.1)
@Diego_Hernandez you need to make sure that you remove the old packages which appear in your yum list. Also, can you share the precise sequence of commands you used to install the C driver and the output of those commands?
@Roberto_Sanchez What are you replying to? I’ve got it to build and link properly; I’m now asking how the project was intended to be used when added as a dependency.
@Diego_Hernandez I was replying to you. I misinterpreted your question as an indication that you built from source to get the latest version and still had a problem.
As to your question (now that I understand that it wasn’t an indication of a problem), the project is designed so that you can either depend on the packages provided by the distribution (e.g., EPEL8/9, Debian, Fedora, etc) assuming that they are recent enough for your requirements. You can also incorporate the components into your own project or handle it as an externally installed dependency on the system. It really depends on the requirements of your project.
Great info. Yeah, the problem was ultimately using an older version. I couldn’t get a pre-built installed even after using yum install epel-release , so building from source got me the latest version. It’s probably just a problem with my machine (GCP)
handle it as an externally installed dependency on the system.
I have a few more questions for the both of you regarding this.
What is the default path prefix for the project? i.e., what happens when user omits the --prefix flag?