Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I use Ubuntu 12.04 on a virtual machine on my MacbookPro. I installed build-essential, mysql-server and libmysqlclient-dev. Both commands 'mysql' and 'mysql_config' work.

However, the following program does not link:

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

int main(int argc,char *argv[]){
    printf("hello world\n");

        MYSQL itsmysql;

        MYSQL* mytemp=0; mytemp=mysql_init(&itsmysql);
            printf("hello world YEP\n");
            printf("hello world NOOOO\n");

    return 0;

I run g++ with the command:

g++ `mysql_config --cflags` `mysql_config --libs` test.cpp

I had this running under a 32 bit version of Ubuntu, but now I have a 64 bits version. The problem occurs both using VirtualBox as with Parallels. The output of 'mysql_config' looks ok.

It seems to me that the linker cannot find the appropriate file/architecture type amongst the libmysqlclient files.

What should I try next?

The error message is 'undefined reference to mysql_init'.

share|improve this question
Ah, sorry, just added it... – user156724 May 8 '13 at 10:14
up vote 1 down vote accepted

Try this instead: worked for me

g++ -o test test.cpp `mysql_config --cflags` `mysql_config --libs`

Then test

Hello world YEP
share|improve this answer
Thanks a million! What also works is: – user156724 May 8 '13 at 13:32
g++ test.cpp mysql_config --cflags mysql_config --libs – user156724 May 8 '13 at 13:33
apparently the mysql_config stuff needs to be at the end of the line :-) – user156724 May 8 '13 at 13:34
Posting "thanks" is not the preferred way of showing appreciation on this site. You can vote up answers you like if it's your question or anywhere once you have 15 reputation. You can also click the tick symbol next to the answer if it's your question, as it is here, to say you have accepted it. – Warren Hill May 8 '13 at 13:40
Well i clicked, i will not 'thank you' again:-) – user156724 May 8 '13 at 13:57

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.