无法编译mongo-c-driver示例 [英] cannot compile mongo-c-driver example

查看:113
本文介绍了无法编译mongo-c-driver示例的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试编写简单的mongo c客户端.源文件(a.c):

I try to write simple mongo c client. Source file (a.c):

#include <stdio.h>
#define MONGO_HAVE_STDINT
#include <mongo.h>

void mongo_init_c(mongo *con)
{
  mongo_init(con);
}

int main() {
  return 0;
}

我尝试使用以下命令进行编译:

And i try to compile it with:

gcc -I/usr/local/include -L/usr/local/lib -lmongoc a.c

但是出现错误:

a.c:(.text+0xd): undefined reference to `mongo_init'

文件/usr/local/include/mongo.h和/usr/local/lib/libmongoc.so存在

Files /usr/local/include/mongo.h and /usr/local/lib/libmongoc.so exists

如何正确编译a.c?

p.s. mongo-2.0.4,gcc-4.6,mongo-c-driver-从github提取

p.s. mongo-2.0.4, gcc-4.6, mongo-c-driver - pulled from github

更新

$ nm/usr/local/lib/libmongoc.so | grep初始化

$ nm /usr/local/lib/libmongoc.so | grep init

000034e0 T _init
0000dd10 T bson_init
0000c740 T bson_init_data
0000c7b0 T bson_init_finished_data
0000dc10 T bson_init_size
0000d060 T bson_iterator_init
0000a5e0 T gridfile_init
00009af0 T gridfile_writer_init
000095e0 T gridfs_init
00010a18 R initialBufferSize
00005f40 T mongo_cursor_init
00008da0 T mongo_env_sock_init
00005d90 T mongo_init
000057b0 T mongo_init_sockets
00004800 T mongo_md5_init
00005e40 T mongo_replica_set_init
00005f00 T mongo_replset_init
00005b80 T mongo_write_concern_init

$ gcc -I/usr/local/include -L/usr/local/lib -Wall -Werror -lmongoc a.c

$ gcc -I/usr/local/include -L/usr/local/lib -Wall -Werror -lmongoc a.c

/tmp/cccuNEp1.o: In function `mongo_init_c':
a.c:(.text+0xd): undefined reference to `mongo_init'

推荐答案

尝试在源文件(例如gcc a.c -lmongoc)之后链接库.这是因为您使用的是传统的单遍链接程序,该链接程序希望满足在命令行上指定的后续对象(而不是先前对象)的依赖性.

Try linking the library after the source file, like gcc a.c -lmongoc. This is because you're using a traditional single-pass linker, which expects to satisfy dependencies with subsequent, not previous, objects specified on the command line.

这篇关于无法编译mongo-c-driver示例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆