PDA

View Full Version : undefined reference to `_imp___Z*****



mgrzyma
17th January 2007, 21:02
Qt 4.2.2 with MinGW 3.4.2 (make is GNU 3.8) on XPpro SP2:
I'm trying a simple program that would connect through ODBC to my MSSQL200 server that runs on my machine;
the C:\Qt\4.2.2\demos\sqlbrowser\release\sqlbrowser.ex e does it perfectly but i want to do my own;

qmake -project and qmake -o Makefile -SQLTest.pro run Ok but after that the "make" first tells me: QtSql - no such file or directory and then after I insert in the Makefile.Debug the "-I"C:/Qt/4.2.2/include/QtSql" it returns a bunch of:

"undefined reference to `_imp___Z*****QSqlDatabase'"

here is my 2 source files:
main.cpp:


#include <QtGui>
#include <QtSql>
#include <QSqlDatabase>
#include <QSqlError>
#include <QSqlError>

#include "connection.h"

int main(int argc, char *argv[])
{
QApplication app(argc, argv);
if (!createConnection()) {
return 1;}
return app.exec();
}

and connection.h:


#ifndef CONNECTION_H
#define CONNECTION_H

#include <QMessageBox>
#include <QSqlDatabase>

inline bool createConnection()
{

QSqlDatabase db = QSqlDatabase::addDatabase("QODBC");
db.setHostName("localhost");
db.setDatabaseName("mydb");
db.setUserName("sa");
db.setPassword("password");

if (!db.open()) {
QMessageBox::warning(0, QObject::tr("Database Connection Error"),
db.lastError().text());
return false;
}
return true;
}
#endif

make gives me exact same message even if i try to copy the entire contents of C:\Qt\4.2.2\demos\sqlbrowser\ into a different directory (how did it copile at install to begin with??)
my path is: "PATH=C:\Qt\4.2.2\bin;C:\Qt\4.2.2\lib;C:\Qt\4.2.2\i nclude;C:\MinGW\bin;C:\WINDOWS\System32"

any ideas?

jpn
17th January 2007, 21:17
To link against the QtSql (http://doc.trolltech.com/4.2/qtsql) module, add this line to your qmake .pro file:

QT += sql
Note: you must re-run qmake after modifying the .pro file to generate the new makefile.

mgrzyma
18th January 2007, 16:57
thanks, it worked;
just curious: without having to do it manually, is there a way to tell qt to place that line 'QT += sql' in the .pro file every time i qmake -project when including <QtSql> (or if i have to delete and re-create the .pro file)?

jpn
18th January 2007, 17:17
It is advisable to run "qmake -project" only once in the beginning of the project and then modify the project file by hand afterwards. There are also free IDEs out there which can handle qmake project files for you. If you're interested, take a look around the forums.. ;)