编译mongoc驱动程序示例程序

编译mongoc驱动程序示例程序,c,mongodb,gcc,compilation,mongo-c-driver,C,Mongodb,Gcc,Compilation,Mongo C Driver,我开始学习使用mongo-c-driver,但在运行时遇到编译问题 gcc -g -Wall -Werror -Isrc --std=c99 mongo-c-driver/src/*.c -I mongo-c-driver/src/ intro.c -lmongoc 我已经看过了另一个stackoverflow帖子,在这里找到的,它没有帮助。这是我的编译器的输出 mongo-c-driver/src/bcon.c:37:12: error: ‘bcon_error’ defined but

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

gcc -g -Wall -Werror -Isrc --std=c99 mongo-c-driver/src/*.c -I mongo-c-driver/src/ intro.c -lmongoc 
我已经看过了另一个stackoverflow帖子,在这里找到的,它没有帮助。这是我的编译器的输出

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
使现代化 还有,如果我决定参加竞选

gcc --std=c99 -Wall intro.c -lmongoc
我的程序将编译,但会给我错误

$ ./a.out 
./a.out: error while loading shared libraries: libmongoc.so.0.7: cannot open shared object file: No such file or directory

我不知道为什么这个示例不会编译,但是如果我复制src目录并创建一个lib目录,其中包含驱动程序的所有已编译二进制文件,那么我可以使用

gcc --std=c99 -o test_program -Llib/ -Isrc/ test.c lib/libmongoc.a
其中目录设置如下

--test.c
--lib
|---libbson.a
|---libbson.so
|---libmongoc.a
|---libmongoc.so
--src
|---bcon.h
|---bon.c
|---env.c
|---env.h
|---etc.

我不知道为什么这个示例不会编译,但是如果我复制src目录并创建一个lib目录,其中包含驱动程序的所有已编译二进制文件,那么我可以使用

gcc --std=c99 -o test_program -Llib/ -Isrc/ test.c lib/libmongoc.a
其中目录设置如下

--test.c
--lib
|---libbson.a
|---libbson.so
|---libmongoc.a
|---libmongoc.so
--src
|---bcon.h
|---bon.c
|---env.c
|---env.h
|---etc.

至少在Fedora18中,解决此问题的另一种方法是运行以下命令

su -c "echo /usr/local/lib > /etc/ld.so.conf.d/mongoc.conf"
su -c "ldconfig"

正确链接mongo-c-driver中的库。

解决此问题的另一种方法,至少在Fedora18中,是运行以下命令

su -c "echo /usr/local/lib > /etc/ld.so.conf.d/mongoc.conf"
su -c "ldconfig"

正确链接mongo-c-driver中的库。

使用-Werror是一种良好的做法,但并非所有项目都这样做。你确定mongo-c-driver源代码应该在没有警告的情况下生成吗?应该是正确的,我已经按照上的所有说明进行了操作。我在该页面上看不到任何提示代码应该在没有警告的情况下生成的内容。他们建议调用gcc省略-Wall-Werror。我怀疑您看到的警告是预期的,因此您需要从命令行中删除-Werror,或者自己修复警告并提交修补程序。后一种方法可能相当令人沮丧。除非您说服项目开始启用警告并将其视为错误,否则它们很可能会在每次提交时意外地添加更多警告。由于这是他们关于如何使用项目的教程,因此不应该生成警告吗?如果您使用他们建议的编译器命令,它可能会生成。您添加了额外的flags-Wall-Werror,因此没有使用建议的build命令。为什么不尝试在没有这些额外标志的情况下构建呢?虽然使用-Werror是一种很好的实践,但并非所有项目都这样做。你确定mongo-c-driver源代码应该在没有警告的情况下生成吗?应该是正确的,我已经按照上的所有说明进行了操作。我在该页面上看不到任何提示代码应该在没有警告的情况下生成的内容。他们建议调用gcc省略-Wall-Werror。我怀疑您看到的警告是预期的,因此您需要从命令行中删除-Werror,或者自己修复警告并提交修补程序。后一种方法可能相当令人沮丧。除非您说服项目开始启用警告并将其视为错误,否则它们很可能会在每次提交时意外地添加更多警告。由于这是他们关于如何使用项目的教程,因此不应该生成警告吗?如果您使用他们建议的编译器命令,它可能会生成。您添加了额外的flags-Wall-Werror,因此没有使用建议的build命令。为什么不尝试在没有这些额外旗帜的情况下建造呢?