我已经安装了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中创建/usr/include/mysql下所有库的回显
发布于 2015-11-06 06:33:55
您可能需要将mysql include添加到编译中,正如您所怀疑的那样:
-I/usr/include/mysql然后就
#include <mysql.h>
#include <my_global.h>发布于 2015-11-06 08:08:01
如果您使用的是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所以在你的编译器中添加这个:-I/usr/local/include并像这样包含这个#include <mysql/my_global.h>
为了解决未定义的引用,你需要喜欢到库的路径。mysqlclient.a/.so并添加此代码以链接库
g++ -g -Wall -I/usr/local/include -L/path_to_lib -lmysqlclient test2.o Test.o -o testhttps://stackoverflow.com/questions/33555997
复制相似问题