sudo apt-get install g++ make
sudo apt-get install libmysqlclient-dev
cd /usr/include/mysql/
sudo find / -name libmysql*
mkdir testmysql
cd testmysql
vim testmysql.cpp
#include<iostream>
#include<mysql.h>
int main()
{
MYSQL mysql;
mysql_init(&mysql);
std::cout << "hello world!\n";
getchar();
system("pause");
return 0;
}
g++ testmysql.cpp -o testmysql
报错,需要指定一些路径,将mysql.h的路径引入进来
g++ testmysql.cpp -o testmysql -I/usr/include/mysql
报错,找一下mysql_init库
g++ testmysql.cpp -o testmysql -I/usr/include/mysql
好啦不报错了
./testmysql
g++ testmysql.cpp -o testmysql -I/usr/include/mysql -lmysqlclient
vim maklefile
make
如果出现这个,先把之前的删掉
rm testmysql
make
编译成功