Step 1: Prepare
Gcc: some class libraries will be installed after installation, so there won't be many errors
Sudo apt-get install g ++, glibc, glibc-source, build-essential, libmysql ++ dev, libmysqlclient15off, libmysqlclient15-dev
I don't know which of the above are actually useful. I have installed them all.
Step 2:
Example Program (others)
# Include <stdio. h>
# Include <stdlib. h>
# Include <string. h>
# Include <mysql/mysql. h>
Int main (){
MYSQL * mysql;
MYSQL_RES * res;
MYSQL_ROW row;
Char query [1024];
Int t, r;
Mysql = mysql_init (NULL );
If (! Mysql_real_connect (mysql, "test", "root ",
"123", "test", 0, NULL, 0 ))
{
Printf ("Error connecting to database: % s \ n", mysql_error (mysql ));
}
Else printf ("Connected... \ n ");
Sprintf (query, "select * from first ");
T = mysql_query (mysql, query );
If (t)
{
Printf ("Error making query: % s \ n ",
Mysql_error (mysql ));
}
Else printf ("Query made... \ n ");
Res = mysql_use_result (mysql );
For (r = 0; r <mysql_field_count (mysql); r ++ ){
Row = mysql_fetch_row (res );
If (row <0) break;
For (t = 0; t <mysql_num_fields (res); t ++)
Printf ("% s", row [t]);
Printf ("\ n ");
}
Mysql_close (mysql );
Return 0;
}
Then gcc test. c-lmysqlclient
In addition, # include may also cause problems. If you need to change it to an absolute path, try again.