3

I would like to install the new update of the MongoDB-C driver but it seems that the compilation logically blocks while including the libbson library (#include <bson.h>) previously installed in the directory "/usr/local/".

How to "link" my libraries correctly in order to use both #include <bson.h> and #include <mongoc.h> ?

John S
  • 231
  • 3
  • 11

1 Answers1

2

Both libmongoc and libbson are automake-based projects now (./configure, make, make install). They additionally install pkg-config *.pc files that can be used to discover library installation and header paths using the pkg-config program. If you have installed to /usr/local, you might need to set PKG_CONFIG_PATH=/usr/local/lib/pkg-config (or lib64) depending if your system automatically includes that path.

A simple way to build against them is to do:

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

If you are in a Makefile, you'll need to shell out first. When using GNU make I typically do:

LIBS := $(shell pkg-config --libs libmongoc-1.0)
CFLAGS := $(shell pkg-config --cflags libmongoc-1.0)
DEBUG := -ggdb
OPTS := -O2
WARNINGS := -Wall -Werror

%.o: %.c %.h
    $(CC) -o $@ -c $(DEBUG) $(WARNINGS) $(OPTS) $(CFLAGS) $*.c

myprog: myprog.o
    $(CC) -o $@ $(DEBUG) $(WARNINGS) $(OPTS) $(LIBS) myprog.o
user2562047
  • 211
  • 1
  • 3
  • The "problem" is that I use a application that compiles itself my .c files. It is therefore not possible for me to use the command "gcc $(pkg-config --cflags --libs libmongoc-1.0) myfile.c" – John S Jan 23 '14 at 21:47
  • You can specify the paths manually using your compilers options. On `gcc` this would be something like `gcc -L/usr/local/lib -I/usr/local/include/libbson-1.0 -I/usr/local/include/libmongoc-1.0 -lbson-1.0 -lmongoc-1.0 my_program.c` – user2562047 Apr 15 '14 at 01:37