pp.c:(.text+0x11): undefined reference to `mysql_init'

1,linux下编译使用mysql c语言API编写的程序报错:

gcc testmysql.c

pp.c:(.text+0x11): undefined reference to `mysql_init'
pp.c:(.text+0x55): undefined reference to `mysql_real_connect'
pp.c:(.text+0x65): undefined reference to `mysql_error'
pp.c:(.text+0x90): undefined reference to `mysql_close'
collect2: ld returned 1 exit status

原因是在编译时没有链接mysqlclient库。

正确的解决方法:gcc testmysql.c -lmysqlclient

2,编译时报错:fatal error: mysql.h: No such file or directory
但是在源文件中#include<mysql.h>这是怎么回事呢

找一下mysql.h文件在哪里,

locate mysql.h

/usr/include/mysql/mysql.h
原来它不在include目录下,所以把源文件里的#include<mysql.h>改成#include<mysql/musql.h>

OK。

原文地址:https://www.cnblogs.com/ymy124/p/2457393.html