我的源码://数据库测试#include#include#include#include#includeintmain(intargc,char**argv){MYSQLmysql;mysql_init(&mysql)...
我的源码:
//数据库测试
#include
#include
#include
#include
#include
int main(int argc, char **argv){
MYSQL mysql;
mysql_init(&mysql);
MYSQL *_stdcall mysql_init(MYSQL *mysql);
if (!mysql_real_connect(&mysql,"localhost","root","","text",0,NULL,0)){
printf("打开数据库失败!\n");
exit(0);
}else{
printf("打开数据库成功!\n");
}
mysql_close(&mysql);
return 0;
}
直接编译错误问题1:
test1.cpp:10: undefined reference to `mysql_init'
test1.cpp:13: undefined reference to `mysql_real_connect'
test1.cpp:20: undefined reference to `mysql_close'
加入编译gcc -o test1 ./test1.cpp -L/usr/local/lib/*.a -lz 错误2:
g++.exe gcc: No such file or directory
去掉gcc 错误3:
multiple definition of `main'
first defined here
cannot find -lz
collect2: ld returned 1 exit status
初学数据库,能给我解释一下为什么?怎么办才可以正确连接到数据库?
求解…………T_T
这几天泪崩ing
ps:因为方便就用的是Wamp里的数据库
展开