当前位置: 技术问答>linux和unix
C和mysql编译出错,帮忙看看
来源: 互联网 发布时间:2015-06-11
本文导语: [root@localhost c]# cat mysql.c #include #include main () { mysql_init(&mysql); if (!mysql_real_connect(&mysql,"host","user","passwd","database",0,NULL,0)) { fprintf(stderr, "Failed to...
[root@localhost c]# cat mysql.c
#include
#include
main () {
mysql_init(&mysql);
if (!mysql_real_connect(&mysql,"host","user","passwd","database",0,NULL,0))
{
fprintf(stderr, "Failed to connect to database: Error: %sn", mysql_error(&mysql));
}
}
出划信息如下,
[root@localhost c]# gcc -L /usr/local/mysql/include/mysql/ mysql.c
mysql.c:2:19: mysql.h: No such file or directory
mysql.c: In function `main':
mysql.c:5: error: `mysql' undeclared (first use in this function)
mysql.c:5: error: (Each undeclared identifier is reported only once
mysql.c:5: error: for each function it appears in.)
就第一个错误而言,mysql.h却实在/usr/local/mysql/include/mysql/下有的,希望大家给点提示,谢谢
#include
#include
main () {
mysql_init(&mysql);
if (!mysql_real_connect(&mysql,"host","user","passwd","database",0,NULL,0))
{
fprintf(stderr, "Failed to connect to database: Error: %sn", mysql_error(&mysql));
}
}
出划信息如下,
[root@localhost c]# gcc -L /usr/local/mysql/include/mysql/ mysql.c
mysql.c:2:19: mysql.h: No such file or directory
mysql.c: In function `main':
mysql.c:5: error: `mysql' undeclared (first use in this function)
mysql.c:5: error: (Each undeclared identifier is reported only once
mysql.c:5: error: for each function it appears in.)
就第一个错误而言,mysql.h却实在/usr/local/mysql/include/mysql/下有的,希望大家给点提示,谢谢
|
gcc -I/usr/local/mysql/include/mysql -lmysqlclient mysql.c
|
变量在使用前要先声明,
MYSQL *mysql;
mysql=mysql_init(0);
MYSQL *mysql;
mysql=mysql_init(0);