简体   繁体   中英

Linker errors when trying to compile Qt application in the CLI on Windows

I have a simple Qt app that I'm trying to compile on Windows in Qt's "Qt 5.5 64-bit for Desktop (MSVC 2013)" prompt with vcvarsall.bat executed.

qmake -version

QMake version 3.0
Using Qt version 5.5.1 in C:/Qt/5.5/msvc2013_64/lib

In my .pro file I don't have anything special, just the sources and headers and:

QT += xml
QT -= gui

When I:

qmake

And:

nmake

It compiles fine, but I get tons of errors like this when linking:

foo.obj : error LNK2019: unresolved external symbol  "__declspec(dllimport
) public: class QJsonValue __thiscall QJsonObject::value(class QString
const &)const "(__imp_?value@QJsonObject@@QBE?AVQJsonValue@@ABVQString@@@Z) 
referenced in function ...

This application compiles and runs fine when I compile it in Qt Creator so what am I missing when trying to compile it in the CLI?

It also compiles in Ubuntu's shell without any problems.

This is because the linker cannot find the DLL. You have to specify the location of the dll for the linker. In the Qt Creator, the DLL is specified by the path to the Qt version. You should add the path to the requiered Qt DLLs to your command

After trying this with CMake I finally realized what the original problem was (CMake gave a clear error about this): I had invoked vcvarsall.bat without amd64 parameter, so the linker tried to use 64-bit libraries with a 32-bit tool chain. Of course the resulting errors were confusing, as usual.

I executed again:

vcvarsall.bat amd64 

...and I was able to compile and link with both qmake and CMake in Qt's command prompt environment using nmake .

On Linux things are a bit more stable as everything defaults to 64-bit and these kind of things don't happen.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM