简体   繁体   English

为什么会出现这些链接错误?

[英]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.

相关问题 当符号明确存在于我链接的静态库中时,为什么会出现链接错误? - Why do I get link errors when the symbol is clearly present in the static library I link against? 当我链接到库时,为什么会出现错误,而不是在构建它时出错? - Why do I get errors when I link to a library, but not when I build it? 为什么在尝试创建 std::numpunct 实例时出现链接错误<char16_t>衍生物? - Why do I get link errors when trying to create an instance of std::numpunct<char16_t> derivative? 为什么在托管代码中出现这些非托管错误? - Why do I get these unmanaged errors in managed code? 为什么在此C ++程序中实现结构时会出错? - Why do I get errors in this C++ program implementing Structures? 为什么我总是在 Codility 中遇到性能错误? - Why do I always get performance errors in Codility? 为什么我使用相同的链接线获得未定义的引用? - Why do I get undefined reference with the same link line? 为什么会出现间歇性的msvc ++链接错误? - Why do I get an intermittent msvc++ link error? 当我要在C ++ Builder Starter中链接静态库TinyXML 2的发行版时,为什么会出现无法解决的外部错误? - Why I get unresolved external errors when I want to link the release version of the static library TinyXML 2 in C++ Builder Starter? 为什么我初始化数组容器的元素大于数组大小时没有出错? - Why I do not get errors when I initialize an array container with more elements than the size of the array?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM