【问题标题】:Mysql library cannot be found找不到Mysql库
【发布时间】:2015-11-05 22:27:46
【问题描述】:

我已经安装了 mysql-devel。相关库住在/usr/inlcude/mysql

这是我要在 Centos7 上编译的示例代码:

#include <my_global.h>
#include <mysql/mysql.h>

int main(int argc, char **argv)
{
  printf("MySQL client version: %s\n", mysql_get_client_info());

  exit(0);
}

错误信息:

Mysql_test.c:1:23: fatal error: my_global.h: No such file or directory
#include <my_global.h>

有什么问题?我是否应该在/usr/include/mysql 下创建所有库的回显到主路径/usr/include

【问题讨论】:

  • 需要修复你的代码 sn-p,不知道你在包含什么

标签: mysql c compilation include centos7


【解决方案1】:

正如您所怀疑的,您可能需要将 mysql include 添加到您的编译中:

-I/usr/include/mysql

那么就

#include <mysql.h>
#include <my_global.h>

【讨论】:

  • 您好,感谢您的回复。这是我在位置标志中发现的:/tmp/ccSOjzqU.o:在函数“main”中:Mysql_test.c:(.text+0x5):未定义对 `mysql_get_client_info'collect2 的引用:错误:ld 返回 1 退出状态 好像头文件没有正确加载。
【解决方案2】:

如果你使用 gcc 包括这样的:

#include <mysql/my_global.h>

如果你使用 gcc 不需要指定-I

取决于 mysql 包含目录在哪里。以及位于哪里my_global.h


编辑:

g++ -g -Wall -I/usr/local/include test2.o Test.o -o test

Soo 添加到您的编译器中:-I/usr/local/include 并像这样包含#include &lt;mysql/my_global.h&gt;


要解决未定义的引用,您需要喜欢库路径。 mysqlclient.a/.so 并添加它来链接库

g++ -g -Wall -I/usr/local/include -L/path_to_lib -lmysqlclient test2.o Test.o -o test

【讨论】:

  • 感谢工作。但是我收到另一个错误,如下所示: /usr/include/mysql/my_global.h:68:23: fatal error: my_config.h: No such file or directory #include 而此时,指定配置头文件的位置将不起作用...
  • 已编辑,尝试这样
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-07-20
  • 2011-04-19
  • 2021-06-23
  • 1970-01-01
  • 1970-01-01
  • 2017-03-28
相关资源
最近更新 更多