Q:

Why do I keep getting undefined symbols when compiling a simple mysql c application on MAC OSX?

I'm using MAC OSX and trying to write a 'test' msyql app that just tests the connection to a local database:
#include <my_global.h>
#include <mysql.h>

int main(void)
{
    MYSQL mysql;

    mysql_init(&mysql);
    mysql_options(&mysql, MYSQL_READ_DEFAULT_GROUP, "examplemysql");
    if(!mysql_real_connect(&mysql, "localhost", "someuser", "somepassword", "sampledb", 0, NULL, 0))
    {
        fprintf(stderr, "Failed to connect to database: Error: %s\n", mysql_error(&mysql));
    }

}

I compile using the command: gcc -I/usr/local/mysql/include -L/usr/local/mysql/lib  mysql.c
I get the following errors

Undefined symbols
  "_mysql_options", referenced from:
        _main in cceohP7E.o
    "_mysql_real_connect", referenced from:
        _main in cceohP7E.o
    "_mysql_init", referenced from:
        _main in cceohP7E.o
    "_mysql_error", referenced from:
        _main in cceohP7E.o
  ld: symbol(s) not found
  collect2: ld returned 1 exit status  

I'm no C/Unix expert, but I want to learn. I know I have a 64-bit architecture running here. Can this be an issue? Let me know what I'm doing wrong.
Thanks.

A:

As the others have mentioned, you're missing the library. Fortunately, MySQL makes this easy via the command line's mysql_config:
gcc `mysql_config --include` mysql.c `mysql_config --libs`

