I compiled the MongoDB C Drivers successfully and run the test scripts also but I am not able to compile the scripts which I am writing myself.
Following is the command and its error output.
$ gcc -Isrc --std=c99 ./src/*.c -I ./src/ tutorial.c -o tutorial -D_POSIX_C_SOURCE=200112L
./src/env_win32.c:27:53: fatal error: ws2tcpip.h: No such file or directory
compilation terminated.
I found that there is no file name ws2tcpip.h in /usr/include directory
Take out the
./src/*.c, that tells gcc to compile all of the c programs in the /src directory which includes some windows only programs.What worked for me was to tell gcc to include the
libmongoc.sothat was built when the drivers were built.The following command worked for me. My drivers are in directory “mongo-c-driver”.
In my opinion the mongodb C API documentation is a little buggy in this area. Also, the latest header files don’t match the source code shown in the tutorial. For example
mongo-insertrequires 4 parameters in the v0.6 headers, but the tutorial shows only 2 parameters.In researching this problem and trying to recreate it by installing mongoDB and the C driver myself I have discovered that v0.6 of the driver broke compatibility with previous version of the API by adding support for
write_concernwhich adds a 4th parameter to themongo_insertfunction (which can be set tonull). Theexample.cprogram provided in thedocs/examplesdirectory does not compile in v0.6. This bug is documented in patch CDRIVER-157 in github for the c-driver.