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?
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With