qt:对"mysql_something @ nr"的未定义引用 [英] qt: undefined reference to 'mysql_something@nr'

查看:102
本文介绍了qt:对"mysql_something @ nr"的未定义引用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我现在真的很困,每次我尝试编译c ++程序时,我都会得到如下输出:

I am really stuck right now, everytime I try to compile my c++ programm I get output like this:

release/dialog.o:dialog.cpp:(.text+0x9e): undefined reference to `mysql_init@4'
release/dialog.o:dialog.cpp:(.text+0xe1): undefined reference to `mysql_real_connect@32'

整日浏览以查找解决方法,教程,其他内容,阅读教程,卸载mingw,mysql服务器,qt并重新安装所有内容.我再次删除了qt并从源代码构建了它...用0.3 mingw-utils reimp.exe和dlltools.exe等转换为libmysql.dll,无济于事.

Browsing the whole day to find workarounds, tutorials, whatever, reading tutorials, uninstalling mingw, mysql server, qt and installing everything again. I deleted qt again and build it from source... converted libmysql.dll with the 0.3 mingw-utils reimp.exe and dlltools.exe and so on, nothing helped.

在使用QT(只是notepad ++和mingw)之前,我也有链接器警告,告诉我一些关于stdcall-fixup-disable的信息,但是这些程序已编译并正常工作.

before using QT (just notepad++ and mingw), I had linker warnings aswell, telling me something bout stdcall-fixup-disable, but the programms compiled and worked.

稍后,我想我将重新安装所有内容,在我什至不知道我从源代码构建qt之前,当前的设置无法比其他安装更好地工作. 有没有一种简单(正常,简单)的方法来使Qt,MinGW,C ++,MySQL5.5协同工作?

later i will reinstall everything again i think, the current setup isn't working better than other installations before i dont even know what i did building qt from source. is there any easy (normal, uncomplicated) way to get Qt, MinGW, C++, MySQL5.5 working together?

edit2:我现在纠正了代码,使它可以正常工作,这是从以下开始的一些最小代码段:

edit2: i corrected the code now, that i got it to work, this is some minimal code snippet to begin with:

#include <QtCore/QCoreApplication>
#include <QMYSQLDriver>
#include <qsqldatabase.h>
#include <QtSql>

int main(int argc, char *argv[])
{
    QCoreApplication app(argc, argv);

    QSqlDatabase db = QSqlDatabase::addDatabase("QMYSQL");
    db.setHostName("localhost");
    // insert other connection options here

    if(!db.open()){
        // dp not open, add some debug text and stuff, exit or retry
    }

    //db should be open at this place, add code here

    return app.exec();
}

推荐答案

听起来您需要将mysql库添加到构建过程中.如果您使用的是Qt的qmake系统,则类似:

It sounds like you need to add the mysql library to the build process. If you're using Qt's qmake system, something like:

LIBS += -L/wherever/the/mysql/lib/is -lmysql

该项目的.pro文件中.

in the .pro file for the project.

这篇关于qt:对"mysql_something @ nr"的未定义引用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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