Mysql C API undefined reference to `mysql_init’

Today I was trying to compile simple program written in C to connect mysql

http://www.ucl.ac.uk/is/mysql/c/
http://www.osix.net/modules/article/?id=517

/tmp/ccetdBsn.o: In function `main’:
sqltest.c:(.text+0x35): undefined reference to `mysql_init’
sqltest.c:(.text+0x77): undefined reference to `mysql_real_connect’
sqltest.c:(.text+0x86): undefined reference to `mysql_error’
sqltest.c:(.text+0xbf): undefined reference to `mysql_query’
sqltest.c:(.text+0xce): undefined reference to `mysql_error’
sqltest.c:(.text+0xfc): undefined reference to `mysql_use_result’
sqltest.c:(.text+0x130): undefined reference to `mysql_fetch_row’
sqltest.c:(.text+0x144): undefined reference to `mysql_free_result’
sqltest.c:(.text+0x14f): undefined reference to `mysql_close’

I found some people also face this problem.

The problem solved after giving

gcc -o test  -L/usr/lib/mysql -lmysqlclient test.c

src: http://lists.mysql.com/mysql/200178

Comments

  1. Hi I got this error even I put the link in Makefile.basic

    Here is my Makefile.basic

    CC=/usr/bin/gcc
    #CC=powerpc-linux-gcc
    CP=/usr/bin/cp
    CFLAGS = -g -Wall $(mysql_config –cflags) $(mysql_config –libs)

    www=/var/www
    htdocs=/htdocs
    cgi_bin=/cgi-bin
    config=/etc/apache2/sites-available/default

    Where it goes wrong ? help me please

  2. Hi I even tried this coz someone told me to try it. but no luck with this line too.
    CFLAGS=-g -Wall $(shell mysql_config –cflags) $(shell mysql_config –libs)

  3. hey
    i tried out the command u have given here, all the errors except one have been cleared for me
    undefined reference to `mysql_free_results' is stl existing.

    I know this is a pretty old post, i would appreciate any help at all.

  4. 1. It may be a version specific issue. You may need to check similar method in new API. Check your mysql header file.

    2. You "res = mysql_use_result(&mysql); " can be return null already. So, try with try catch block.

Leave a Reply

Your email address will not be published. Required fields are marked *