【问题标题】:Can't find mysql/mysql.h after upgrading to 5.6升级到5.6后找不到mysql/mysql.h
【发布时间】:2014-02-27 22:45:34
【问题描述】:

昨天我使用this page 上的说明将 mysql 从 5.5 升级到 5.6,一切正常,mysql 客户端连接,我没有丢失任何数据或类似的坏事。

今天我开始编写一个使用 mysql 库的 C 程序。我的制作失败了,因为我没有来自mysql_config --cflagsmysql_config --libs 的正确标志,我已经修复了这些标志。所以现在我的make文件有这样定义的标志:

mysqlflags = -I/opt/mysql/server-5.6/include  -fPIC -g -fabi-version=2 -fno-omit-frame- pointer -fno-strict-aliasing -DMY_PTHREAD_FASTMUTEX=1
mysqllibs  = -L/opt/mysql/server-5.6/lib -lmysqlclient -lpthread -lm -lrt -ldl

但是当我编译时出现错误:

In file included from ./headers/controllers/comments.h:12:0,
             from src/controllers/comments.c:1:
./headers/db.h:4:26: fatal error: mysql/mysql.h: No such file or directory

所以我继续检查了我的包含文件夹,果然没有标题:

ls /opt/mysql/server-5.6/include/mysql
client_authentication.h  innodb_priv.h      plugin_auth_common.h  plugin_ftparser.h.pp           service_my_plugin_log.h  service_thd_alloc.h
client_plugin.h                    plugin_auth.h         plugin.h                    service_my_snprintf.h    service_thd_wait.h
client_plugin.h.pp       plugin_audit.h     plugin_auth.h.pp       plugin_validate_password.h  service_mysql_string.h   service_thread_scheduler.h
get_password.h           plugin_audit.h.pp  plugin_ftparser.h     psi                         services.h               thread_pool_priv.h`

如果我查找一个目录,则在包含文件夹本身中

 ls /opt/mysql/server-5.6/include/
big_endian.h                 keycache.h       my_byteorder.h  my_global.h   mysql_com_server.h  mysql_version.h    plugin_validate_password.h  typelib.h
byte_order_generic.h         little_endian.h  my_compiler.h   my_list.h     mysqld_ername.h     my_sys.h           sql_common.h
byte_order_generic_x86_64.h  m_ctype.h        my_config.h     my_net.h      mysqld_error.h      my_xml.h           sql_state.h
byte_order_generic_x86.h     m_string.h       my_dbug.h       my_pthread.h  mysql_embed.h       plugin_audit.h     sslopt-case.h
decimal.h                    my_alloc.h       my_dir.h        mysql         mysql.h             plugin_ftparser.h  sslopt-longopts.h
errmsg.h                     my_attribute.h   my_getopt.h     mysql_com.h   mysql_time.h        plugin.h           sslopt-vars.h

看到那里的 mysql.h 让我说,哦,好吧,它只是在错误的地方。我试着做一个

#include <mysql.h> 看看它是否会捡起它,没有骰子。我尝试将 mysql.h 文件复制到 mysql/ 文件夹,但这也没有做任何事情,当我执行 locate mysql.h 时,它也只显示了包含文件夹中的那个。

谁能告诉我一些关于 mysql 5.6 与 5.5 开发变化的文档? documentation 没有说我还没有做过的事情

编辑: 这是makefile输出的相关部分

cc -I/opt/mysql/server-5.6/include/mysql  -fPIC -g -fabi-version=2 -fno-omit-frame-pointer -fno-strict-aliasing -DMY_PTHREAD_FASTMUTEX=1 -I./headers -std=gnu99 -pedantic -Wall -Wextra -Werror -g -c src/database/db.c -o obj/db.o     
In file included from src/database/db.c:1:0:
./headers/db.h:4:26: fatal error: mysql/mysql.h: No such file or directory
compilation terminated.

我还重新运行了mysql --cflags 以确保我在上面写错了,实际输出是

-I/opt/mysql/server-5.6/include/mysql -fPIC -g -fabi-version=2 -fno-omit-frame-pointer -fno-strict-aliasing -DMY_PTHREAD_FASTMUTEX=1

这就是我用来编译但仍然收到错误的东西

【问题讨论】:

标签: mysql c makefile


【解决方案1】:

你已经添加了

/opt/mysql/server-5.6/include/mysql

作为包含路径,然后在你的头文件中,你#include <mysql/mysql.h>。这是相对于包含路径的,因此(除了默认的包含路径),编译器正在寻找具有该路径的文件

/opt/mysql/server-5.6/include/mysql/mysql/mysql.h

它不会找到。您应该将代码更改为 #include <mysql.h>,或者将传递给编译器的包含路径更改为 /opt/mysql/server-5.6/include

编辑:

抱歉,我刚刚意识到mysql.h 位于/opt/mysql/server-5.6/include/mysql.h,而不是/opt/mysql/server-5.6/include/mysql/mysql.h。 您必须同时执行以下操作:将 /opt/mysql/server-5.6/include 添加为包含路径将您的代码更改为 #include <mysql.h>

【讨论】:

  • 我已经尝试了这两种方法,都只做#include <mysql.h>并将路径更改为最后只有/include,同样的问题,它找不到mysql.h跨度>
  • 抱歉,我搞混了。请问两者都做好吗?我还编辑了答案。
  • 酷。这修复了它,尽管它迫使我在我所有的 cc 调用中包含 $(mysqlflags) 以包含包含 db.h 的 anything 这对我来说很奇怪,因为我以前不需要这样做。不过谢谢!
  • 我想以前,您的 MySQL 头文件位于默认包含路径的某个位置。 mysql.h 会自动找到。但是现在,由于它位于不同的位置,您必须告诉编译器在哪里可以找到它。
  • 当我之前用 apt-get 安装所有东西时(对于 5.5),我很确定它安装到 /usr/include 中,而不是现在的 /opt 目录中。我可以移动东西,但我想我现在还不错。有时 mysql 和其他程序交互的方式太容易了。不过感谢您的所有帮助!
猜你喜欢
  • 2012-03-06
  • 1970-01-01
  • 1970-01-01
  • 2015-10-11
  • 2013-07-29
  • 2013-12-08
  • 2016-08-29
  • 2019-03-05
  • 2013-11-21
相关资源
最近更新 更多