How can I compile Mongodb-c-driver?

I use

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

for mongodb c compilation code and then

 LD_LIBRARY_PATH=/usr/local/lib ./mongotest 

for start.

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 to run a program without LD_LIBRARY_PATH = / usr / local / lib, is this correct? How can I debug mongodb c driver programs?

+6
source share
1 answer

The path /usr/local/lib must be in /etc/ld.so.conf or in one of the files in the /etc/ld.so.conf.d/ directory. Thus, the mongoc library will go into the cache when the ldconfig command is ldconfig as root.

You can check if the mongoc library mongoc in the dynamic linker cache by running this command

 ldconfig -p | grep mongoc 

If you can run your program without explicitly specifying LD_LIBRARY_PATH.

Another way to check if your executable is properly linked is to get the binding information using the ldd command. It will print all linked libraries.

 ldd mongotest 

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

+9
source

Source: https://habr.com/ru/post/971589/


All Articles