Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 20 Apr 2004 11:41:19 -0700
From:      "Derrick Ryalls" <freebsd@fbsdsolutions.com>
To:        freebsd-questions@freebsd.org
Subject:   Accessing MySQL from C
Message-ID:  <A99A5AC30F74624388EE5F757BA58A20D7A2F0@RED-MSG-50.redmond.corp.microsoft.com>

next in thread | raw e-mail | index | archive | help
I am trying to write a little program that will talk to my existing mysql db
server (4.1.1), but am having compile issues.

The code is:

#include <stdio.h>
#include <mysql.h>

#define HOST "localhost"
#define USERNAME "test"
#define PASSWORD "test"
#define DB "pollphp"

MYSQL *conn;

int main()
{
        conn = mysql_init(NULL);
}

And here are various compile attempts:

# gcc -o sqltest sqltest.c
sqltest.c:2: mysql.h: No such file or directory
# gcc -L/usr/local/include/mysql -o sqltest sqltest.c
sqltest.c:2: mysql.h: No such file or directory

If I change the above include to:
#include </usr/local/include/mysql/mysql.h>

I get this on compile:

# gcc -o sqltest sqltest.c
/tmp/ccrC5KFf.o: In function `main':
/tmp/ccrC5KFf.o(.text+0xc): undefined reference to `mysql_init'

And if I and the -l flag:
# gcc -o sqltest -l/usr/local/lib/mysql/libmysqlclient.so sqltest.c
/usr/libexec/elf/ld: cannot find -l/usr/local/lib/mysql/libmysqlclient.so
(I also tried libmysqlclient.a and libmysqlclient)

I have gotten as far as I can with the man pages for gcc, and google isn't
helping much.  Does anyone know how I can compile a program that talks to
mysql?

TIA

-Derrick



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?A99A5AC30F74624388EE5F757BA58A20D7A2F0>