开发者

Why do I get these link errors?

When I try running a Qt application with the following main.cpp file:

#include <QApplication>
#include "ui_checkabder.h"
#include <QDialog>
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
Ui::CheckAbder ui;
QDialog *dialog = new QDialog;
ui.setupUi(dialog);
dialog->show();
return app.exec();
}

I get the following errors:

c:/QtSDK/Desktop/Qt/4.7.3/mingw/lib/libqtmaind.a(qtmain_win.o):-1: In function `WinMain@16':

`c:/ndk_buildrepos/qt-desktop/src/winmain/qtmain_win.cpp:131: error: undefined reference to qMain(int, char **)`

:-1: error: collect2: ld retu开发者_Python百科rned 1 exit status

And, abder.pro looks like this:

######################################################################
# Automatically generated by qmake (2.01a) Mon Apr 18 09:52:56 2011
######################################################################

TEMPLATE = app
TARGET = 
DEPENDPATH += .
INCLUDEPATH += .

# Input
FORMS += checkabder.ui

How can I solve those errors? Provided that I'm using Qt Creator.

Thanks.


main.cpp is not built. Add the following to your .pro file:

 SOURCES += main.cpp


I crossed paths with this problem myself just now.

I got it when i tried to make the console window for my application disappear.

http://lists.trolltech.com/qt-interest/2005-12/thread00170-0.html

Be sure that the linker links qtmain.lib to your program, that's what fixed this for me.

Old Stuff:

I'd guess that your library was compiled with some different settings regarding what char is.

If this were Visual Studio, I'd select the treat w_char as built in type to false.

edit:

What Naszta said made me think the following: try adding

int qMain(int argc, char * array [])
{
    return 0;
}

If this works, something else might be broken (IMO).


How about

QT += core gui

in your .pro file?


Try add the followings:

#ifdef WIN32
#include <windows.h>
int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow )
{
    return main( nCmdShow, &lpCmdLine ); 
}
#endif
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜