Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

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");

    //init
        {
        MYSQL itsmysql;

        MYSQL* mytemp=0; mytemp=mysql_init(&itsmysql);
        if(mytemp){
            printf("hello world YEP\n");
            }
        else{   
            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
add comment

1 Answer

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

./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
add comment

Your Answer

 
discard

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.