无法动态链接MongoDB C驱动库
我真的很困惑可能是什么问题。我把 libbson.a libbson.so libmongoc.a libmongoc.so 与我的可执行文件位于同一文件夹中。头文件也位于同一文件夹中。 然后我用这个来make
它:
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
编译工作,但是当我尝试运行它时,动态链接器抱怨! ldd main
显示了这一点:(为什么它只抱怨 lbson,而不显示 lmongoc?)
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)
有关 .a 文件的信息有点稀疏,但据我所知,链接应该以与 .so 文件相同的方式进行,对吗?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
将 .a 文件视为目标文件解决了这个问题。但是,也应该可以将其视为库文件。这还是不行。
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.