开发者

How does one resolve link error with Qt?

I'm new to Qt, and trying to compile and link a simple "Hello, World" program using Microsoft's "CL.exe". Any advice on how to do this?

The program is:

#include <QtGui>

int main ( int argc, char * argv [] )
    {
    QApplication app ( argc, argv ) ;
    QLabel label ( "Hello, world!" ) ;
    label.show() ;
    return app.exec() ;
    }

I compile and link with:

C:\PROGRA~1\MICROS~1.0\VC\bin\cl.EXE -nologo -Zm200 -Zc:wchar_t- -O2 -MD ^
-W3 -w34100 -w34189 -DUNICODE ^
-DWIN32 -DQT_LARGEFILE_SUPPORT -DQT_NO_DEBUG -DQT_GUI_LIB -DQT_CORE_LIB ^
-DQT_THREAD_SUPPORT -DQT_NO_DYNAMIC_CAST ^
-I"C:\Qt\2010.05\qt\include\QtCore" ^
-I"C:\Qt\2010.05\qt\include\QtGui" ^
-I"C:\Qt\2010.05\qt\include" ^
-I"." ^
-I"C:\Qt\2010.05\qt\include\ActiveQt" ^
-I"release" ^
-I"C:\Qt\2010.05\qt\mkspecs\win32-msvc2008" ^
-I"C:\Progra~1\MICROS~1.0\VC\include" ^
Hello.cpp ^
/link /LIBPATH:"C:\Qt\2010.05\qt\lib" ^
/LIBPATH:"C:\Progra~1\MICROS~1.0\VC\lib" ^
/LIBPATH:"C:\Progra~1\MID05A~1\VC\PLATFO~1\Lib"

My linker errors include:

Hello.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) pub
lic: virtual __thiscall QApplication::~QApplication(void)" (__imp_??1QApplicatio
n@@UAE@XZ) referenced in function _main
Hello.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) pub
lic: virtual __thiscall QLabel::~QLabel(void)" (__imp_??1QLabel@@UAE@XZ) referen
ced in function _main
Hello.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) pub
开发者_StackOverflowlic: static int __cdecl QApplication::exec(void)" (__imp_?exec@QApplication@@SAH
XZ) referenced in function _main
Hello.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) pub
lic: void __thiscall QWidget::show(void)" (__imp_?show@QWidget@@QAEXXZ) referenc
ed in function _main
.
.
.

My Hello.pro file contains:

######################################################################
# Automatically generated by qmake (2.01a) Mon Dec 13 15:58:13 2010
######################################################################

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

# Input
SOURCES += Hello.cpp


You should be linking against QtCore and QtGui libraries but you don't. What does your .pro file look like?


Edited to add after the .pro file was posted: Your .pro file looks all right. You're not overwriting the QT variable which by default includes core gui, which should result in QtCode and QtGui being linked to. It's also evident by the fact that both QtCore and QtGui are present in your include paths.

I haven't used cl.exe with Qt but you could try adding LIBS += -lQtCore -lQtGui to force linking to QtCore and QtGui. (There's probably a more elegant fix though.)


Your PATH should include the qt/bin directory. In a Visual Studio Command Prompt you should do a "qmake hello.pro" which creates three makefiles, and then "nmake". If you want to use vcxproj files, you should change your TEMPLATE to vcapp.


trying to compile and link a simple "Hello, World" program using Microsoft's "CL.exe"

Hey i think there are easier ways of getting qt applications compiled on visual studio. Instead of struggling with commandline options why not install the qt visual studio addin that makes compiling projects soooooooo easy? Just a suggestion :)

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜