add a -lmysql to your linking command.
Mysql Plusplus wrote:
>Hi everybody,
>i have got a problem while linking a simple C++ program wwose main function is to
> access the mysql database.
>
>#include<stdio.h>
>#include<connection.h>
>#include<mysql.h>
>#include<mysql++.h>
>
>MYSQL *conn;
>
>int main()
>{
> bool x;
> conn = mysql_init(NULL);
> x = mysql_real_connect(conn,host,username,password,database,0,NULL,0);
>
> MYSQL_RES *res_set;
> MYSQL_ROW row;
> unsigned int i;
>
> mysql_query(conn,"SELECT * FROM employee");
> res_set = mysql_store_result(conn);
>
> while((row = mysql_fetch_row(res_set)) != NULL)
> {
> printf("%s\n",row[i] != NULL ? row[i] : "NULL");
> }
>
> mysql_close(conn);
> return 1;
>}
>
>The compilation is successful but main problem occurs when we link the program.
>The following error occurs:
>
>[prompt]$ gcc -I/home/divick/temp1 -I/home/divick/temp1/mysql.h test1.cpp
>/tmp/ccaPf1Fg.o(.text+0x16): In function `main':
>: undefined reference to `mysql_init'
>/tmp/ccaPf1Fg.o(.text+0x43): In function `main':
>: undefined reference to `mysql_real_connect'
>/tmp/ccaPf1Fg.o(.text+0x61): In function `main':
>: undefined reference to `mysql_query'
>/tmp/ccaPf1Fg.o(.text+0x72): In function `main':
>: undefined reference to `mysql_store_result'
>/tmp/ccaPf1Fg.o(.text+0x83): In function `main':
>: undefined reference to `mysql_fetch_row'
>/tmp/ccaPf1Fg.o(.text+0xe1): In function `main':
>: undefined reference to `mysql_close'
>/tmp/ccaPf1Fg.o(.text+0x10e): In function
> `__static_initialization_and_destruction_0(int, int)':
>: undefined reference to `std::ios_base::Init::Init[in-charge]()'
>/tmp/ccaPf1Fg.o(.text+0x14b): In function `__tcf_0':
>: undefined reference to `std::ios_base::Init::~Init [in-charge]()'
>/tmp/ccaPf1Fg.o(.eh_frame+0x11): undefined reference to `__gxx_personality_v0'
>collect2: ld returned 1 exit status
>
>Please, can anyone help me with that?
>