QtSql test application
As a lab rat, I'm afraid of starting a new thread, however, Qt forum is so huge I can't even get started finding a similar problem to mine. I've seen several "Symbol(s) not found..." thread, but none of them related to what I'm trying to do, which is to compile the following very basic program, just to test Qt's connectivity with SQL.
MainWindow::MainWindow(QWidget *parent) :
printf( "Runs like a charm\n" );
printf( "rodou\n" );
QSqlDatabase db = QSqlDatabase::addDatabase("QPSQL");
bool ok = db.open();
printf( "Conexão com banco de dados: %\n", ok );
As you'll promptly recognize, the first part of the code was generated by Qt. I added the dbConnect() function to isolate my test code, just that.
And then, it stopped compiling, with the compiler emiting the dreaded two messages:
":-1: error: symbol(s) not found for architecture x86_64"
":-1: error: collect2: ld returned 1 exit status"
I'm running Qt Creator 4.7.4 on Lion 10.7.2.
Any hints would be more than a help for me now. Thanks
Have you linked your SQL module with Qt?
Welcome to DevNet and the forums. Don't hesitate to open a new thread (especially if you indicate that you've searched already). Everyone is friendly here and we take a strong focus on a good atmosphere without flamewars or similar habits that makes people go away.
Regarding your actual problem, can you also post the contents of your .pro file please. And it would be good to know if you use some precompiled Qt (either the libs package or from the SDK) or some manually compiled Qt.
Then, in Qt Creator, go to the compiler output tab (the 4th on the bottom), there you find some additional infos regarding the error, including the method names/symbols that are missing.
Additionally, did you install the PostgreSQL libs from a package or did you build it yourself?
Oh... and just to clean up some confusion: It's most likely Qt Creator 2.3.1 and Qt libs 4.7.4 - both are independent software packages :-)
Wow. Thanks Volker. That was a complete and guiding help.
My .pro file (no pun intended) is as follows:
QT += core gui
TARGET = dbTst
TEMPLATE = app
SOURCES += main.cpp
HEADERS += mainwindow.h
FORMS += mainwindow.ui
I guess I'm lost in regard to how Qt suggests me to use QtSql. It was my understanding that whenever I #included "QtSql", the linker/compiler would automatically grab internal libs (since there is a "QPSQL" qualifier).
I didn't "install" any PostgreSQL libs, explicit, but I do have PG server running on the machine. I'll transfer pqlib.
Let me experiment more with the Compile Output.
Well, I can be very wrong, but this message from the compiler should clarify a lot...
../QtSDK/Desktop/Qt/474/gcc/include/QtCore/qglobal.h:320:6: warning: #warning "This version of Mac OS X is unsupported"
mainwindow.cpp: In destructor 'virtual MainWindow::~MainWindow()':
Doh! Will install Qt for Windows and see how it goes on.
You will at least have to add "sql" to your QT variable:
QT += core gui sql
This adds the QtSql library to the link step.
Qt is organized in modules, each module that you use must be named in the QT variable of the .pro file.
Lion is still relatively new in respect to Qt, the upcoming 4.8 release should contain full support. For the time being, I think you can ignore the warning.
The error message you received ("symbol(s) not found for architecture x86_64") usually indicates that you link against a library that does not contain all necessary architecture variants for your application. On Mac OS X a binary (application executable or library) usually contains code for more than one architecture. On Lion this usually includes i386 (Intel 32 bit) and x86_64 (Intel 64 bit). On older OS X versions you can also have ppc (PowerPC 32 bit) and ppc64 (PowerPC 64bit).
Qt itself, when installed from the prebuilt libs or the SDK, only contains x86_64 code. This is what you are building your application against. If you use external libs (like the PostgreSQL libs) that do not contain x86_64 code, your link step will fail.
In that case you have two choices:
First you can either install a x86_64 version of the external lib or build that yourself.
Second you rebuild Qt manually and include at least the i386 architecture. You have to exclude the x86_64 part from your application then.
The warning message about the Mac Os version being unsupported is not related to the linker error. To get rid of it, specify the Mac Os target SDK as 10.6 as described here: http://doc.qt.nokia.com/latest/deployment-mac.html#architecture-dependencies