首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >编译Mongo c驱动程序示例程序

编译Mongo c驱动程序示例程序
EN

Stack Overflow用户
提问于 2013-06-11 00:13:37
回答 2查看 2.3K关注 0票数 1

我开始学习如何使用mongo-c-driver,但我在运行时遇到了编译问题

代码语言:javascript
复制
gcc -g -Wall -Werror -Isrc --std=c99 mongo-c-driver/src/*.c -I mongo-c-driver/src/ intro.c -lmongoc 

我已经看过另一个stackoverflow帖子了,在这里找到了cannot compile mongo-c-driver example,它没有帮助。以下是我的编译器的输出

代码语言:javascript
复制
mongo-c-driver/src/bcon.c:37:12: error: ‘bcon_error’ defined but not used [-Werror=unused-function]
mongo-c-driver/src/bcon.c:378:13: error: ‘bcon_json_print’ defined but not used [-Werror=unused-function]
cc1: all warnings being treated as errors
mongo-c-driver/src/env.c: In function ‘mongo_env_socket_connect’:
mongo-c-driver/src/env.c:319:21: error: storage size of ‘ai_hints’ isn’t known
mongo-c-driver/src/env.c:340:5: error: implicit declaration of function ‘getaddrinfo’ [-Werror=implicit-function-declaration]
mongo-c-driver/src/env.c:342:9: error: implicit declaration of function ‘gai_strerror’ [-Werror=implicit-function-declaration]
mongo-c-driver/src/env.c:347:60: error: dereferencing pointer to incomplete type
mongo-c-driver/src/env.c:348:36: error: dereferencing pointer to incomplete type
mongo-c-driver/src/env.c:348:55: error: dereferencing pointer to incomplete type
mongo-c-driver/src/env.c:348:76: error: dereferencing pointer to incomplete type
mongo-c-driver/src/env.c:354:45: error: dereferencing pointer to incomplete type
mongo-c-driver/src/env.c:354:62: error: dereferencing pointer to incomplete type
mongo-c-driver/src/env.c:368:20: error: dereferencing pointer to incomplete type
mongo-c-driver/src/env.c:381:5: error: implicit declaration of function ‘freeaddrinfo’ [-Werror=implicit-function-declaration]
mongo-c-driver/src/env.c:319:21: error: unused variable ‘ai_hints’ [-Werror=unused-variable]
cc1: all warnings being treated as errors
intro.c: In function ‘main’:
intro.c:9:7: error: enumeration value ‘MONGO_CONN_SUCCESS’ not handled in switch [-Werror=switch]
intro.c:9:7: error: enumeration value ‘MONGO_CONN_ADDR_FAIL’ not handled in switch [-Werror=switch]
intro.c:9:7: error: enumeration value ‘MONGO_CONN_BAD_SET_NAME’ not handled in switch [-Werror=switch]
intro.c:9:7: error: enumeration value ‘MONGO_CONN_NO_PRIMARY’ not handled in switch [-Werror=switch]
intro.c:9:7: error: enumeration value ‘MONGO_IO_ERROR’ not handled in switch [-Werror=switch]
intro.c:9:7: error: enumeration value ‘MONGO_SOCKET_ERROR’ not handled in switch [-Werror=switch]
intro.c:9:7: error: enumeration value ‘MONGO_READ_SIZE_ERROR’ not handled in switch [-Werror=switch]
intro.c:9:7: error: enumeration value ‘MONGO_COMMAND_FAILED’ not handled in switch [-Werror=switch]
intro.c:9:7: error: enumeration value ‘MONGO_WRITE_ERROR’ not handled in switch [-Werror=switch]
intro.c:9:7: error: enumeration value ‘MONGO_NS_INVALID’ not handled in switch [-Werror=switch]
intro.c:9:7: error: enumeration value ‘MONGO_BSON_INVALID’ not handled in switch [-Werror=switch]
intro.c:9:7: error: enumeration value ‘MONGO_BSON_NOT_FINISHED’ not handled in switch [-Werror=switch]
intro.c:9:7: error: enumeration value ‘MONGO_BSON_TOO_LARGE’ not handled in switch [-Werror=switch]
intro.c:9:7: error: enumeration value ‘MONGO_WRITE_CONCERN_INVALID’ not handled in switch [-Werror=switch]
cc1: all warnings being treated as errors

更新

另外,如果我决定参选

代码语言:javascript
复制
gcc --std=c99 -Wall intro.c -lmongoc

我的程序可以编译,但会给出错误

代码语言:javascript
复制
$ ./a.out 
./a.out: error while loading shared libraries: libmongoc.so.0.7: cannot open shared object file: No such file or directory
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2013-06-18 01:43:30

解决这个问题的另一种方法,至少在fedora 18中,是运行以下命令

代码语言:javascript
复制
su -c "echo /usr/local/lib > /etc/ld.so.conf.d/mongoc.conf"
su -c "ldconfig"

正确链接来自mongo-c-driver的库。

票数 4
EN

Stack Overflow用户

发布于 2013-06-11 01:22:42

我不知道为什么这个示例不能编译,但是如果我复制src目录并创建一个lib目录,那么我可以使用

代码语言:javascript
复制
gcc --std=c99 -o test_program -Llib/ -Isrc/ test.c lib/libmongoc.a

其中的目录设置如下

代码语言:javascript
复制
--test.c
--lib
|---libbson.a
|---libbson.so
|---libmongoc.a
|---libmongoc.so
--src
|---bcon.h
|---bon.c
|---env.c
|---env.h
|---etc.
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/17028354

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档