Frage

I am beginning to learn about using the mongo-c-driver, but I have been having compilation issues when I run

gcc -g -Wall -Werror -Isrc --std=c99 mongo-c-driver/src/*.c -I mongo-c-driver/src/ intro.c -lmongoc 

I have already looked over the other stackoverflow post, found here cannot compile mongo-c-driver example , it did not help. Here is the output from my compiler

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

Update

Also, if I decide to run

gcc --std=c99 -Wall intro.c -lmongoc

my program will compile, but will give me the error

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

Lösung

Another way to fix this issue, at least in fedora 18, is to run the following commands

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

which correctly link the libraries from mongo-c-driver.

Andere Tipps

I have no idea why this example will not compile, but if I copy the src directory and make a lib directory, where all of the compiled binaries for the driver lie, the I can compile the program using

gcc --std=c99 -o test_program -Llib/ -Isrc/ test.c lib/libmongoc.a

where the directories are setup as follows

--test.c
--lib
|---libbson.a
|---libbson.so
|---libmongoc.a
|---libmongoc.so
--src
|---bcon.h
|---bon.c
|---env.c
|---env.h
|---etc.
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top