簡體   English   中英

編譯Mongo c驅動程序示例程序

[英]Compiling Mongo c driver example program

我開始學習使用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的例子 ,它沒有幫助。 這是我的編譯器的輸出

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

解決此問題的另一種方法,至少在fedora 18中,是運行以下命令

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

從mongo-c-driver正確鏈接庫。

我不知道為什么這個例子不會編譯,但如果我復制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.

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM