fatal error: mysql.h: No such file or directory
2017-02-27 10:12
549 查看
转自:http://tangmingjie2009.iteye.com/blog/1521088
我是在Ubuntu系统下测试的
此系统下,mysql安装: apt-get install mysql-server 等了有10多分钟
然后又装了mysql-client: apt-get install mysql-client
还不够还需要mysql的开发包: apt-get install libmysql++
没有权限的话sudo 你懂的
敲下代码
C代码
#include <stdlib.h>
#include "mysql.h"
int main(void){
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","111111","mysql",0,NULL,0);
if(conn_ptr){
printf("Connection success\n");
}else{
printf("Connection failed\n");
}
mysql_close(conn_ptr);
return EXIT_SUCCESS;
}
编译
gcc -o testmysql testmysql.c
Java代码
testmysql.c:4:19: fatal error: mysql.h: No such file or directory
compilation terminated.
然后修改gcc -o testmysql testmysql.c -I/usr/include/mysql/
C代码
/tmp/ccW7qMov.o: In function `main':
testmysql.c:(.text+0x11): undefined reference to `mysql_init'
testmysql.c:(.text+0x8f): undefined reference to `mysql_real_connect'
testmysql.c:(.text+0xc0): undefined reference to `mysql_close'
collect2: ld returned 1 exit statu
最后修改
C代码
gcc -o testmysql testmysql.c -I/usr/include/mysql/ -lmysqlclient -Wall -g
成功
我是在Ubuntu系统下测试的
此系统下,mysql安装: apt-get install mysql-server 等了有10多分钟
然后又装了mysql-client: apt-get install mysql-client
还不够还需要mysql的开发包: apt-get install libmysql++
没有权限的话sudo 你懂的
敲下代码
C代码
#include <stdlib.h>
#include "mysql.h"
int main(void){
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","111111","mysql",0,NULL,0);
if(conn_ptr){
printf("Connection success\n");
}else{
printf("Connection failed\n");
}
mysql_close(conn_ptr);
return EXIT_SUCCESS;
}
编译
gcc -o testmysql testmysql.c
Java代码
testmysql.c:4:19: fatal error: mysql.h: No such file or directory
compilation terminated.
然后修改gcc -o testmysql testmysql.c -I/usr/include/mysql/
C代码
/tmp/ccW7qMov.o: In function `main':
testmysql.c:(.text+0x11): undefined reference to `mysql_init'
testmysql.c:(.text+0x8f): undefined reference to `mysql_real_connect'
testmysql.c:(.text+0xc0): undefined reference to `mysql_close'
collect2: ld returned 1 exit statu
最后修改
C代码
gcc -o testmysql testmysql.c -I/usr/include/mysql/ -lmysqlclient -Wall -g
成功
相关文章推荐
- linux php添加pdo_mysql 扩展时报错 fatal error: ext/mysqlnd/mysqlnd.h: No such file or directory
- cppsql.cpp:2:19: fatal error: mysql.h: No such file or directory
- ubuntu中fatal error: mysql.h: No such file or directory
- fatal error: mysql/mysql.h: No such file or directory
- linuxC无法访问mysql.h:fatal error: mysql.h: No such file or directory compilation terminated.
- linux php添加pdo_mysql 扩展时报错 fatal error: ext/mysqlnd/mysqlnd.h: No such file or directory
- Linux下修复“fatal error: jsoncpp/json/json.h: No such file or directory”
- python/caffe/_caffe.cpp:10:31: fatal error: numpy/arrayobject.h: No such file or directory
- Linux下修复“fatal error: jsoncpp/json/json.h: No such file or directory” 分类: C++ | 标签: Linux,jsonjson
- BUG!!!======> 编译安装lua 时 lua.c:67:31: fatal error: readline/readline.h: No such file or directory
- 出现问题:fatal error: ltdl.h: No such file or directory
- caffe编译:fatal error: pyconfig.h: No such file or directory #include "pyconfig.h"
- PIL的正确安装(“_imagingft.c:73:31: fatal error: freetype/fterrors.h: No such file or directory”)
- hello.cpp:1:24: fatal error: QApplication: No such file or directory
- src/core/ngx_regex.h:15:18:fatal error: pcre.h: No such file or directory
- ImportError: libmysqlclient_r.so.16: cannot open shared object file: No such file or directory
- fatal error: hdf5.h: No such file or directory
- caffe时编译出错: fatal error: caffe/proto/caffe.pb.h: No such file or directory
- error: /usr/include/features.h:324:26: fatal error: bits/predefs.h: No such file or directory
- 编译安装lua 时 lua.c:67:31: fatal error: readline/readline.h: No such file or directory