[英]Why do I get these link errors?
When I try running a Qt
application with the following main.cpp
file: 当我尝试使用以下main.cpp
文件运行Qt
应用程序时:
#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 returned 1 exit status
And, abder.pro
looks like this: 而且, abder.pro
看起来像这样:
######################################################################
# 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
. 前提是我正在使用Qt Creator
。
Thanks. 谢谢。
main.cpp is not built. main.cpp未构建。 Add the following to your .pro file: 将以下内容添加到您的.pro文件中:
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 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. 确保链接器将qtmain.lib链接到您的程序,这对我来说就是固定的。
Old Stuff: 老东西:
I'd guess that your library was compiled with some different settings regarding what char is. 我猜想您的库是用关于char是什么的一些不同设置编译的。
If this were Visual Studio, I'd select the treat w_char as built in type to false. 如果这是Visual Studio,则选择将内置类型的w_char视为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). 如果这样做有效,则可能会损坏其他内容(IMO)。
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
How about 怎么样
QT += core gui
in your .pro file? 在您的.pro文件中?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.