在ubuntu下安装好了mysql,想测试一下C语言连接mysql,写了一个connect.c文件,如下
#include <stdlib.h>
#include <stdio.h>
#include "mysql.h"
int main(int argc,char *argv[]) {
MYSQL *conn_ptr;
conn_ptr = mysql_init(NULL);
if(!conn_ptr) {
fprintf(stderr,"mysql_init failed\n");
return EXIT_FAILURE;
}
conn_ptr = mysql_real_connect(conn_ptr,"localhost","root","xxxxxx","foo",0,NULL,0);
if(conn_ptr)
printf("Connection success\n");
else
printf("Connection failed\n");
mysql_close(conn_ptr);
return EXIT_SUCCESS;
}
结果报错,libmysqlclient.so.20:cannot open shared object file:no such file or directory,
百度了一下似乎是共享库未添加。但是这个库我已经放在usr/lib/mysql下了啊,为什么还报错?