PDA

View Full Version : Visual Studio compiling Qt code report LNK2019



threedts167
9th November 2015, 07:44
Hi, everybody.

I'm new to Qt and I'm currently working on a module of a project(an assignment of a course in my school). The UI is created using Qt (by another fellow in my group), so I have to use classes like QString and QDir and so on. But I'd like to use VS instead of QtCreator to do the coding since I'm not drawing the UI.

I downloaded the latest Qt 5.5 open-source version for Windows from its website. Its root folder is D:\Qt\5.5\msvc2013_64. Inside I found the "lib" folder with many ".lib" files and "include" folder with relevant headers. So I imported both of them into my VS project. And I added the "Qt5Cored.lib" to my VS project's "Additional Dependencies" option of the linker.

I wrote a very simple test to see if this configuration works. (Using QString and QDir).

But the linker constantly report LNK2019 on QString::QString and QDir::setPath and many other Qt's stuff.

What am I doing wrong or I simply can't do Qt-coding in VS without an add-in?

Thanks in advance.

ChrisW67
9th November 2015, 10:10
You need to match the compiler, bit-ness (is that a word?), and debug/release mode the Qt libraries were built with. The Qt5Cored.dll is a debug library and you have a 64-bit MS VC2013 version of Qt. Are you attempting to compile your program as a debug version with a 64-bit MSVC 2013?

threedts167
9th November 2015, 14:49
Yes I'm using 64-bit Windows and Visual Studio 2013 (I guess it's also 64-bit because I searched this and Microsoft doesn't provide 32 or 64 VS installer seperately.).

I'm compiling a Debug configuration of my program in Visual Studio 2013.

I installed Qt 5.5 using the online-installer from Qt's official website. According to the installer's reference manual page, it will match the compiler on my system and select the matched pre-built Qt libraries to download. I checked this by clicking Tools->Options->Build & Run in QtCreator and I got the following list of compilers detected (and used by QtCreator):
Microsoft Visual C++ Compiler 12.0 (x86) MSVC
Microsoft Visual C++ Compiler 12.0 (amd64) MSVC
Microsoft Visual C++ Compiler 12.0 (x86_amd64) MSVC
Microsoft Visual C++ Compiler 12.0 (x86_arm) MSVC
Microsoft Visual C++ Compiler 12.0 (amd64_arm) MSVC

The same piece of code can compile and run perfectly on my machine without any problem if I use QtCreator instead of Visual Studio. So I'm guessing there's some configuration options that I'm missing in my VS project.

Lesiok
9th November 2015, 15:48
Install Visual Studio Addin (http://download.qt.io/official_releases/vsaddin/qt-vs-addin-1.2.4-opensource.exe). This tool integrades Qt and Visual Studio IDE.

threedts167
10th November 2015, 05:39
I have Installed the Visual Studio Addin.

But I still got the same linker errors, and I turned on the /VERBOSE switch I can see that Qt5Cored.lib is marked as "unused library", which is strange because my test code is as follows.


#include <iostream>

#include <QtCore/QtCore>

using namespace std;

int main()
{
QString strPath1 = "D:/TestCDir";
QString strPath2 = "D:/TestCDir/Tmp";
QDir dir;
dir.setPath(strPath1);
if (!dir.exists())
dir.mkpath(strPath1);
dir.setPath(strPath2);
if (dir.count() == 0)
dir.rmpath(strPath2);
else
cout << dir.count() << endl;
dir.setPath(strPath1);
dir.rmpath(strPath1);
return 0;
}

ChrisW67
13th November 2015, 09:03
If you build your project in release mode then Qt5Cored.dll will be unused because the "d" in the library name means "debug". Your program should be linked to Qt5Core.dll