2

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?

jamjam
  • 3,171
  • 7
  • 34
  • 39
aishwarya
  • 1,970
  • 1
  • 14
  • 22

2 Answers2

2

The Mongo-C-driver dynamic library build is now fixed for Mac OS X (Lion), see

https://github.com/mongodb/mongo-c-driver/commit/ea89d8fa966ccf601a67e1507e67e829775f6bcb

https://jira.mongodb.org/browse/CDRIVER-158

Gary Murakami
  • 3,392
  • 1
  • 16
  • 20
1

There seems to be an issue on the mac - link against the static library instead.

geakie
  • 1,458
  • 9
  • 9