Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I compile the Mongodb-c-driver program?

I use

gcc -o mongotest mongotest.c $(pkg-config --cflags --libs libmongoc-1.0)

for compilation mongodb c driver code, and then

LD_LIBRARY_PATH=/usr/local/lib ./mongotest

for run.

If I try without LD_LIBRARY_PATH=/usr/local/lib I have

./mongotest: error while loading shared libraries: libmongoc-1.0.so.0: cannot open shared object file: No such file or directory

How can I run program without LD_LIBRARY_PATH=/usr/local/lib, Is it correct to do so? How can I debug mongodb c driver programs?

like image 449
Sizario Avatar asked Jul 01 '14 10:07

Sizario


People also ask

What is MongoDB C driver?

The MongoDB C Driver, also known as “libmongoc”, is a library for using MongoDB from C applications, and for writing MongoDB drivers in higher-level languages. It depends on libbson to generate and parse BSON documents, the native data format of MongoDB.


1 Answers

The path /usr/local/lib should be in /etc/ld.so.conf or in one of the files in /etc/ld.so.conf.d/ directory. So the library mongoc will get into the cache when you issue command ldconfig as root.

You can check if library mongoc is in dynamic linker cache by executing this command

ldconfig -p | grep mongoc

If it is you are safe to run your program without explicitly specifying LD_LIBRARY_PATH.

Other way to check if your executable is correctly linked is by getting the linking information with ldd command. It will print all linked libraries.

ldd mongotest

If you can see /usr/local/lib/libmongoc.so.[numbers] that means it is linked with mongoc library.

like image 137
Grzegorz Żur Avatar answered Oct 09 '22 22:10

Grzegorz Żur