I’m really perplexed as to what the problem could be. I put libbson.a libbson.so libmongoc.a
libmongoc.so into the same folder as my executable. The header files are also in the same folder.
Then I make it with this:
CFLAGS += -I. -std=c99 $(shell pkg-config --cflags json) \
$(shell pkg-config --cflags glib-2.0)
LDFLAGS += -Wl,-rpath,/usr/local/lib $(shell pkg-config --libs glib-2.0) \
$(shell pkg-config --libs json) -lpcre -L. -Wl,-rpath,. \
-lmongoc -lbson
all: main.o
gcc $(LDFLAGS) -ggdb main.o -o main
main.o: main.c
gcc $(CFLAGS)-ggdb -c main.c
Compiling works, but when I try to run it the dynamic linker complains!
ldd main shows this: (why does it only complain about lbson for example and not show lmongoc at all?)
linux-vdso.so.1 => (0x00007fffb2fc9000)
libglib-2.0.so.0 => /lib64/libglib-2.0.so.0 (0x00007fd0dd9bd000)
libjson.so.0 => /usr/local/lib/libjson.so.0 (0x00007fd0dd7b5000)
libpcre.so.0 => /lib64/libpcre.so.0 (0x00007fd0dd57f000)
libbson.so.0.4 => not found
libc.so.6 => /lib64/libc.so.6 (0x00007fd0dd212000)
librt.so.1 => /lib64/librt.so.1 (0x00007fd0dd009000)
/lib64/ld-linux-x86-64.so.2 (0x00007fd0ddcaf000)
libpthread.so.0 => /lib64/libpthread.so.0 (0x00007fd0dcdec000)
Information about .a files is a little sparse, but as far as I was able to find out, linking should happen the same way as with .so files right?
Treating the .a file like an object file solved it. It should however be possible to treat it like a library file too. This still doesn’t work.