PDA

View Full Version : Suddenly getting 'undefined ref to 'WinMain@16'



Doug Broadwell
1st December 2008, 23:59
After doing a:

qmake -project "CONFIG += debug", "win32: CONFIG += console"
qmake n2.pro

(which I've done many times in the past, I'm getting:

make -f Makefile.Debug
make[1]: Entering directory `C:/Data/Qt/mverse/n2'
g++ -mthreads -Wl,-enable-stdcall-fixup -Wl,-enable-auto-import -Wl,-enable-runtime-pseudo-reloc -Wl,-subsystem,console -o "debug\n2.exe" debug\q
extserialbase.o debug\qextserialport.o debug\win_qextserialport.o -L"c:\Data\Qt\4.2.3\lib" -lQtGuid4 -lQtCored4
C:/Data/Qt/MinGW/bin/../lib/gcc/mingw32/3.4.2/../../../libmingw32.a(main.o)(.text+0x106):main.c: undefined reference to `WinMain@16'
collect2: ld returned 1 exit status
make[1]: *** [debug\n2.exe] Error 1

I'm not sure how to go about debugging this.

Thanks, Doug

pgorszkowski
2nd December 2008, 05:18
Can you show us your main.c file?

JPNaude
2nd December 2008, 06:52
Hi,

I've been getting similar types of errors, don't have a message now, but in my case the problems are also in mingw libraries or in qt libraries. I've only experienced this with Qt Creater 0.9 Alpha, so I assumed there's something wrong with the libraries shipped with it.

I haven't tried to solve it yet though,
Cheers
Jaco

jpn
2nd December 2008, 18:10
Adding or removing "CONFIG += console" requires rebuilding the application (or at least the source file containing main() function). Unfortunately rebuilding doesn't happen automatically because the source file doesn't change.

Doug Broadwell
3rd December 2008, 00:05
Here's the code for my main.cpp:



#include <QApplication>
#include <QtGui>
#include "MainWindow.h"
#include "comm.h"
#include "state.h"
#include "error.h"
#include "main.h"

#include "ctl_cfg_assoc.h"



//- GLOBAL OBJECT POINTERS -//

MainWindow* mw;
QScrollArea* sa;


QByteArray qbaEmpty;




//----------------------------------------------------------------------------------
// REIMPLEMENTATION OF QApplication::notify() TO CATCH OTHERWISE UNCAUGHT ERRORS |
//---------------------------------------------------------------------------------------------------------
// *FIXME* We want to remove this for production.

qMyApp::qMyApp( int argc, char* argv[] ) : QApplication( argc, argv ) {};

qMyApp::~qMyApp() {};

//---------------------------------------------------------------------------------------------------------

bool qMyApp::notify( QObject* qoReceiver, QEvent* qeEvent ) {

try {

return QApplication::notify( qoReceiver, qeEvent );

} catch( Fatal_Error& E ) {

qDebug() << "\n" << E.Error_String() << "\n";
throw;

} catch( Base_Error& E ) {

qDebug() << "\n" << E.Error_String() << "\n";
throw;

} catch( ... ) {

qDebug("\nUnknown Error Caught\n");
throw;
}
};
//---------------------------------------------------------------------------------------------------------







//---------
// MAIN |
//---------------------------------------------------------------------------------------------------------

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


//-- CREATE APPLICATION OBJECT --//

qMyApp app(argc, argv);

//-- CREATE STATE OBJECT --//

Init_State(); // Must come before creating the Serial Port.

//-- CREATE SERIAL PORT OBJECT --//

Init_SerialPort( 2 ); // Create COM2.

//-- CREATE CtlCfgAssoc OBJECT --//

Init_CtlCfgAssoc();

//-- CREATE MAIN WINDOW OBJECT WITH SCROLLBARS --//

mw = new MainWindow;
sa = new QScrollArea;
sa->setWidget( mw );
sa->show();

//-- RUN --//

return app.exec();
}
//---------------------------------------------------------------------------------------------------------


But I haven't changed anything in it from before when it was working. It seems to be an issue with 'main.c' in libmingw32.a but I don't know what it's doing.

Doug

jpn
3rd December 2008, 08:15
As I told you, rebuild the application:

make clean
qmake
make

Doug Broadwell
3rd December 2008, 18:11
Sorry if I wasn't clear; I have rebuilt the application and still get this error.

Doug

Doug Broadwell
3rd December 2008, 20:07
Found the problem (but not what is causing it). For some reason the 'qmake -project' is making a project file with only a subset of the header and source files in it, when I add all the files (I assume that missing the file with main() in it was causing the error) and running qmake it seems to be fine again.

Doug

jpn
4th December 2008, 18:11
Well, "qmake -project" is supposed to be something that you run once in the beginning of a project to generate an initial project file. It's not intended to be used to maintain the project file.