MySQL和C:未定义的引用`_mysql_init @ 4“| [英] MySQL and C : undefined reference to `_mysql_init@4'|

查看:203
本文介绍了MySQL和C:未定义的引用`_mysql_init @ 4“|的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图写一个简单的脚本C到从MySQL数据库中获取值,但它抛出这个错误未定义的参考`_mysql_init @ 4''

不知道如果我不链接到东西,我应该是什么?我的C知识是有限的...

我在Windows上使用code块,这是我的code:

 的#include<&WINSOCK.H GT;
#包括c为C:\\ mysql的\\包括\\ mysql.h中>
#包括LT&;&stdio.h中GT;
#包括LT&;&string.h中GT;诠释的main()
{
   MYSQL mysql的;
   MYSQL_RES *杂志;
   MYSQL_ROW行;   焦炭查询[80];
   mysql_init(安培; mysql的);
   mysql_real_connect(安培; mysql的,本地主机,用户,合格,DB,0,NULL,0);
   sprintf的(查询,选择SRC,DST FROM ipaudit);
   mysql_real_query(安培; mysql的,查询(无符号整数)的strlen(查询));
   RES =了mysql_use_result(安培; mysql的);
   而(行= mysql_fetch_row(RES))
    的printf(%s%SN,行[0],行[1]);
   了mysql_free_result(RES);
   返回0;
}


解决方案

未定义的引用指与连接器有问题。功能 mysql_init()不是你的code的一部分,已经在库编译。你必须告诉链接器通过指定表示code是库包括code该功能。

我不知道如何来指定code座图书馆,对不起

修改

一个快速谷歌搜索如何在code块指定库返回的有趣的结果:)

I'm trying to write a simple script for C to get values from a MySQL database, but it's throwing this error 'undefined reference to `_mysql_init@4''

Don't know if I'm not linking to something I should be? My C knowledge is limited...

I'm using Code Blocks on Windows, here's my code:

#include <winsock.h>
#include <C:\mysql\include\mysql.h>
#include <stdio.h>
#include <string.h>

int main()
{
   MYSQL mysql;
   MYSQL_RES *res;
   MYSQL_ROW row;

   char query[80];
   mysql_init(&mysql);
   mysql_real_connect(&mysql,"localhost","user","pass","db",0,NULL,0);
   sprintf(query,"SELECT src,dst FROM ipaudit");
   mysql_real_query(&mysql,query,(unsigned int)strlen(query));
   res = mysql_use_result(&mysql);
   while(row = mysql_fetch_row(res))
    printf("%s %sn",row[0],row[1]);
   mysql_free_result(res);
   return 0;
}

解决方案

undefined reference refers to a problem with the linker. The function mysql_init() is not part of your code and is already compiled in a library. You have to tell the linker to include the code for that function by specifying the library where said code is.

I don't know how to specify libraries in Code Blocks, sorry

Edit

A quick Google search for how to specify libraries in Code Blocks returned a interesting result :)

这篇关于MySQL和C:未定义的引用`_mysql_init @ 4“|的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆