C语言连接MYSQL问题

写了一个连接MYSQL的C程序,出现以下错误信息:

cc -I/usr/include/mysql -Wall -g  -lmysqlclient -g -L/usr/lib  connect1.c   -o connect1
/tmp/ccykDQvd.o: In function `main':
/home/jie/Beginning Linux Program/ch08/connect1.c:9: undefined reference to `mysql_init'
/home/jie/Beginning Linux Program/ch08/connect1.c:15: undefined reference to `mysql_real_connect'
/home/jie/Beginning Linux Program/ch08/connect1.c:24: undefined reference to `mysql_close'
collect2: ld 返回 1
make: *** [connect1] 错误 1

从出错信息看,是链接库找不到的问题。
因此查看了 /usr/lib 下的库文件发现:


[jie@jie:/usr/lib]$ls libmysqlclient*
libmysqlclient.a    libmysqlclient_r.so     libmysqlclient_r.so.16.0.0  libmysqlclient.so.16
libmysqlclient_r.a  libmysqlclient_r.so.16  libmysqlclient.so           libmysqlclient.so.16.0.0

链接库路径没错,库文件也有,怎么就找不到呢?
附上简单源码:
01.#include<stdlib.h>                                                                  

02.#include <stdio.h>

03.

04.#include "mysql.h"

05.

06.int main(int argc, char *argv[]) {

07.   MYSQL *conn_ptr;

08.

09.   conn_ptr = mysql_init(NULL);

10.   if (!conn_ptr) {

11.      fprintf(stderr, "mysql_init failed\n");

12.      return EXIT_FAILURE;

13.   }

14.  

15.   conn_ptr = mysql_real_connect(conn_ptr, "localhost", "jie", "edgeyang",

16.                                                     "children", 0, NULL, 0);

17.

18.   if (conn_ptr) {

19.      printf("Connection success\n");

20.   } else {

21.      printf("Connection failed\n");

22.   }

23.

24.   mysql_close(conn_ptr);

25.

26.   return EXIT_SUCCESS;

27.}
复制代码另外,使用的系统刚升级为UBUNTU 11.10,MYSQL 版本信息如下:

Server version                5.1.58-1ubuntu1
Protocol version        10
Connection                Localhost via UNIX socket
UNIX socket                /var/run/mysqld/mysqld.sock
Uptime:                        5 hours 41 min 40 sec

在系统升级之前,同样的程序是可以连接到MYSQL的!

你可能感兴趣的:(mysql,function,undefined,reference,信息)