linux下c语言操作MYSQL编译报错
/tmp/ccBs9sBr.o(.text+0xd):Infunction`Connect_Mysql'::undefinedreferenceto`mysql_init...
/tmp/ccBs9sBr.o(.text+0xd): In function `Connect_Mysql':
: undefined reference to `mysql_init'
/tmp/ccBs9sBr.o(.text+0x32): In function `Connect_Mysql':
: undefined reference to `mysql_options'
/tmp/ccBs9sBr.o(.text+0x54): In function `Connect_Mysql':
: undefined reference to `mysql_close'
/tmp/ccBs9sBr.o(.text+0x82): In function `Connect_Mysql':
: undefined reference to `mysql_real_connect'
/tmp/ccBs9sBr.o(.text+0xa4): In function `Connect_Mysql':
: undefined reference to `mysql_close'
collect2: ld returned 1 exit status
编译的时候报上面的错误。 展开
: undefined reference to `mysql_init'
/tmp/ccBs9sBr.o(.text+0x32): In function `Connect_Mysql':
: undefined reference to `mysql_options'
/tmp/ccBs9sBr.o(.text+0x54): In function `Connect_Mysql':
: undefined reference to `mysql_close'
/tmp/ccBs9sBr.o(.text+0x82): In function `Connect_Mysql':
: undefined reference to `mysql_real_connect'
/tmp/ccBs9sBr.o(.text+0xa4): In function `Connect_Mysql':
: undefined reference to `mysql_close'
collect2: ld returned 1 exit status
编译的时候报上面的错误。 展开
展开全部
找不到库的路径,或者你的include的路径不正确,请检查下你的配置的include路径是否包含有你的include文件。
还有注意编译时:
cc -o test test.c 【libmysqlclient.a】 -g ...
要写上这个库...
或
gcc -o test -L/usr/lib/mysql -lmysqlclient test.c
还有注意编译时:
cc -o test test.c 【libmysqlclient.a】 -g ...
要写上这个库...
或
gcc -o test -L/usr/lib/mysql -lmysqlclient test.c
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
#include <mysql/mysql.h>
#include <stdio.h>
#include <stdlib.h>
#define HOST "localhost"
#define USERNAME "用户名"
#define PASSWORD "密码"
#define DATABASE "指定的数据库"
#define SQL_QUERY "SELECT * FROM 表名"
int main(void)
{
MYSQL mysql;
MYSQL_ROW row;
MYSQL_RES *result;
unsigned int num_fields;
unsigned int i;
mysql_init(&mysql);
if(!mysql_real_connect(&mysql, HOST, USERNAME, PASSWORD, DATABASE, 0, NULL, 0))
{
printf("Connection failed,%s\n",mysql_error(&mysql));
}
mysql_query(&mysql, "set names utf8");
if(!mysql_query(&mysql, SQL_QUERY))
{
result = mysql_store_result(&mysql);
if(!result)
{
perror("result error.");
exit(1);
}
num_fields = mysql_num_fields(result);
while(row = mysql_fetch_row(result))
{
for(i=0; i<num_fields; i++)
{
printf("%s\t",row[i]);
}
printf("\n");
}
mysql_free_result(result);
}
mysql_close(&mysql);
return 0;
}
编译命令:
gcc -o mysql_test mysql_test.c -lmysqlclient
运行命令:
./mysql_test
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询