I am trying to write a small C based client for mongo db for my application. Let me start by saying that I haven't programmed in C in a long time now, so may be the problem I am facing is a very basic one! I just can not get my code to compile :-)
I am using a 64 bit Apple Macbook Pro (OSX Lion). The gcc is:
Target: i686-apple-darwin11
Thread model: posix
gcc version 4.2.1 (Based on Apple Inc. build 5658) (LLVM build 2335.15.00)
I git cloned the mongo c driver, did a git checkout to 0.6 and then ran make.
make
make install
make test
The tests ran fine and the libraries were installed correctly in /usr/local/lib/ with the .h files going correctly to /usr/local/include.
Then I copy pasted a piece of code into a file called data.c as follows:
#include <stdio.h>
#include "mongo.h"
int main() {
mongo conn[1];
int status = mongo_connect(conn, "127.0.0.1", 27017);
return 0;
}
Nothing fancy, just trying to open a connection. When I try to compile this, I get the following error:
gcc --std=c99 -I/usr/local/include -L/usr/local/lib -o data data.c -lmongoc
Undefined symbols for architecture x86_64:
"_mongo_connect", referenced from:
_main in ccjPPPVs.o
ld: symbol(s) not found for architecture x86_64
collect2: ld returned 1 exit status
What am I doing wrong?