h文件可以';找不到 我试图在Ubuntu 12.04中安装C++和MySQL之间的连接。我已经安装了mysql客户端、mysql服务器、libmysqlclient15 dev、libmysql++-dev。但是当我试图编译代码时,我得到了一个错误:mysql.h没有这样的文件。我在文件夹里看了看,里面有mysql.h文件,我不明白为什么找不到。这是我的密码: /* Simple C program that connects to MySQL Database server*/ #include <mysql.h> #include <stdio.h> main() { MYSQL *conn; MYSQL_RES *res; MYSQL_ROW row; char *server = "localhost"; char *user = "root"; //set the password for mysql server here char *password = "*********"; /* set me first */ char *database = "Real_flights"; conn = mysql_init(NULL); /* Connect to database */ if (!mysql_real_connect(conn, server, user, password, database, 0, NULL, 0)) { fprintf(stderr, "%s\n", mysql_error(conn)); exit(1); } /* send SQL query */ if (mysql_query(conn, "show tables")) { fprintf(stderr, "%s\n", mysql_error(conn)); exit(1); } res = mysql_use_result(conn); /* output table name */ printf("MySQL Tables in mysql database:\n"); while ((row = mysql_fetch_row(res)) != NULL) printf("%s \n", row[0]); /* close connection */ mysql_free_result(res); mysql_close(conn); }
您必须让编译器知道mysql.h文件的位置。这可以通过在编译之前提供头的路径来实现。在IDE中,您有一个设置,可以在其中指定这些路径 这为您提供了编译时使用哪些选项的更多信息 第二个问题 您需要链接这些库。链接器需要知道库文件的位置,其中包含您使用的mysql函数的实现h文件可以';找不到 我试图在Ubuntu 12.04中安装C++和MySQL之间的连接。我已经安装了mysql客户端、mysql服务器、libmysqlclient15 dev、libmysql++-dev。但是当我试图编译代码时,我得到了一个错误:mysql.h没有这样的文件。我在文件夹里看了看,里面有mysql.h文件,我不明白为什么找不到。这是我的密码: /* Simple C program that connects to MySQL Database server*/ #include <mysql.h> #include <stdio.h> main() { MYSQL *conn; MYSQL_RES *res; MYSQL_ROW row; char *server = "localhost"; char *user = "root"; //set the password for mysql server here char *password = "*********"; /* set me first */ char *database = "Real_flights"; conn = mysql_init(NULL); /* Connect to database */ if (!mysql_real_connect(conn, server, user, password, database, 0, NULL, 0)) { fprintf(stderr, "%s\n", mysql_error(conn)); exit(1); } /* send SQL query */ if (mysql_query(conn, "show tables")) { fprintf(stderr, "%s\n", mysql_error(conn)); exit(1); } res = mysql_use_result(conn); /* output table name */ printf("MySQL Tables in mysql database:\n"); while ((row = mysql_fetch_row(res)) != NULL) printf("%s \n", row[0]); /* close connection */ mysql_free_result(res); mysql_close(conn); },c++,mysql,ubuntu-12.04,mysql-connector,C++,Mysql,Ubuntu 12.04,Mysql Connector,您必须让编译器知道mysql.h文件的位置。这可以通过在编译之前提供头的路径来实现。在IDE中,您有一个设置,可以在其中指定这些路径 这为您提供了编译时使用哪些选项的更多信息 第二个问题 您需要链接这些库。链接器需要知道库文件的位置,其中包含您使用的mysql函数的实现 这为您提供了有关如何链接库的更多信息。libmysqlclient devUbuntu包中的mysql.h文件位于/usr/include/mysql/mysql.h 这不是编译器的标准搜索路径,但是/usr/include是
这为您提供了有关如何链接库的更多信息。
libmysqlclient dev
Ubuntu包中的mysql.h
文件位于/usr/include/mysql/mysql.h
这不是编译器的标准搜索路径,但是/usr/include
是
您通常会在代码中使用mysql.h
头,如下所示:
#include <mysql/mysql.h>
只用
$ apt-get install libmysqlclient-dev
将自动拉取最新的libmysqlclient18 dev
我见过旧版本的libmysqlclient-dev(如15)将mysql.h放在奇怪的位置,例如/usr/local/include等
否则,就做一个
$ find /usr/ -name 'mysql.h'
并将带有-I标志的
mysql.h
文件夹路径放在make文件中。不干净但可以用。我想你可以试试这个gcc-I/usr/include/mysql*.c-L/usr/lib/mysql-lmysqlclient-o*用于CentOS/RHEL:
yum install mysql-devel -y
您可能没有包括mysql头的路径,我想在一些unix系统上可以在/usr/include/mysql中找到。看,这可能会有帮助 顺便说一句,与上面的问题有关,关于句法结构。可以将以下内容添加到~/.vimrc中:
let b:syntastic_c_cflags = '-I/usr/include/mysql'
您可以随时查看github上开发人员的详细信息。享受吧 适用于使用Eclipse IDE的用户。 在安装完整的MySQL以及MySQL客户端和MySQL服务器以及任何MySQL开发库之后 您需要告诉Eclipse IDE关于以下内容
- 在哪里可以找到mysql.h
- 在哪里可以找到libmysqlclient库
- 路径到搜索libmysqlclient库
$ gcc dbconnect.c -o dbconnect -lmysqlclient
$ ./dbconnect
yum install mysql
-lmysqlclient是必须的
我个人建议使用以下符号,而不是使用-i编译标志
#include <mysql/mysql.h>
#包括
这对我很有效
$ gcc dbconnect.c -o dbconnect -lmysqlclient
$ ./dbconnect
yum install mysql
它将安装mysql客户端,然后
pip install mysqlclient
我试图找到gcc.conf文件,将
-I/usr/include/mysql
添加到搜索路径中,以便syntastic(vim语法检查器)可以找到头文件。这可能/推荐吗?@mattyTpain我不熟悉syntastic,但我认为它至少应该支持搜索/usr/include
。您应该使用mysql/mysql.h
进行include操作,因此不应该要求syntastic在/usr/include/mysql
中搜索。您尝试了添加此内容,但仍然没有成功。我试图从源代码编译pdo_mysql,并且安装了mariadb-devel包。完整命令失败:cc-I-I/usr/include^Cmysql-I-I/tmp/PDO_-MYSQL-1.0.2-DPHP_-ATOM_-INC-I/tmp/PDO_-MYSQL-1.0.2/include-I/tmp/PDO_-MYSQL-1.0.2-I/tmp/PDO_-MYSQL-1.0.2-I/usr/include/php/main-I/usr/include/php/main-I/usr/include/php/TSRM-I/usr-I/usr/include/I/Zend/ext/index/html/php-html/php-php-html/php-php-php-php-php-include/html/php-php-php-php-php-php-php-php-php-php-php-php-php-c/tmp/PDO_MYSQL-1.0.2/PDO_MYSQL.c-fPIC-DPIC-o.libs/PDO_MYSQL.o