我尝试编写简单的 mongo c 客户端。源文件(ac):
#include <stdio.h>
#define MONGO_HAVE_STDINT
#include <mongo.h>
void mongo_init_c(mongo *con)
{
mongo_init(con);
}
int main() {
return 0;
}
我尝试编译它:
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 存在
我怎样才能正确编译ac?
ps mongo-2.0.4、gcc-4.6、mongo-c-driver - 从 github 提取
更新
$ nm /usr/local/lib/libmongoc.so | grep 初始化
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 ac
/tmp/cccuNEp1.o: In function `mongo_init_c':
a.c:(.text+0xd): undefined reference to `mongo_init'