Код: Выделить всё
// Заголовочные файлы
#include <mysql/mysql.h>
#include <iostream>
#include <cstdio>
#include <cstdlib>
using namespace std;
int main(){
MYSQL_RES *result;
MYSQL_ROW row;
MYSQL *connection, mysql;
int state;
mysql_init(&mysql);
connection = mysql_real_connect(&mysql,"localhost","username","password","database",0,NULL,0); //Открытие соединения
state = mysql_query(connection, "SELECT * FROM clients");
result = mysql_store_result(connection);
printf("Строк: \n", mysql_num_rows(result));
while( ( row = mysql_fetch_row(result)) != NULL ) {
printf("id: %s, значение: %s\n", (row[0] ? row[0] : "NULL"), (row[1] ? row[1] : "NULL"));
}
mysql_free_result(result); // закрыть соединение
mysql_close(connection);
printf("Koнец, работы.\n");
}При компиляции выдает:
/tmp/ccy9cr1d.o: In function `main':
sql-prog.cpp:(.text+0x23): undefined reference to `mysql_init'
sql-prog.cpp:(.text+0x67): undefined reference to `mysql_real_connect'
sql-prog.cpp:(.text+0x7f): undefined reference to `mysql_query'
sql-prog.cpp:(.text+0x8f): undefined reference to `mysql_store_result'
sql-prog.cpp:(.text+0x9f): undefined reference to `mysql_num_rows'
sql-prog.cpp:(.text+0x109): undefined reference to `mysql_fetch_row'
sql-prog.cpp:(.text+0x125): undefined reference to `mysql_free_result'
sql-prog.cpp:(.text+0x131): undefined reference to `mysql_close'
collect2: ld returned 1 exit status
Чего теперь делать-то? Компилил и gcc и g++ - все без толку!