昨天我按照 this page 上的说明将 mysql 从 5.5 升级到 5.6。一切都很顺利,mysql 客户端连接上了,我没有丢失任何数据或类似的问题。
今天我开始编写一个使用 mysql 库的 C 程序。我的制作失败了,因为我没有来自 mysql_config --cflags
的正确标志和 mysql_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
它也只显示了 include 文件夹中的那个。
任何人都可以向我指出一些关于针对 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
这就是我用来编译但仍然出现错误的原因
最佳答案
你已经添加了
/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>
.
关于mysql - 升级到 5.6 后找不到 mysql/mysql.h,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22069856/