PDA

View Full Version : Link error when compiling Qt 5.1.0 project in Visual Studio 2010



xtal256
2nd January 2014, 02:18
Hi,

A while ago i upgraded from Qt 4.x to 5.1.0. I then got a new computer (Windows 7, 64 bit) on which i installed a clean 5.1.0. But i have never been able to successfully compile my project with 5.1.0. Now i've come back to the project to try again, and it all seems to be compiling ok, but when it gets to linking it says it cannot find "qtmaind.lib":


2>------ Rebuild All started: Project: Window Detective, Configuration: Debug Win32 ------
2>Build started 2/01/2014 1:05:13 PM.
2>_PrepareForClean:
2> Deleting file "Debug\obj\Window Detective.lastbuildstate".
2>InitializeBuildStatus:
2> Touching "Debug\obj\Window Detective.unsuccessfulbuild".
2>CustomBuild:
2> Moc'ing ...
...
2> Rcc'ing qt_resources.qrc...
2>ClCompile:
2> Window.cpp
...
2> Generating Code...
2>LINK : fatal error LNK1104: cannot open file 'qtmaind.lib'
2>
2>Build FAILED.
2>
2>Time Elapsed 00:07:50.17
========== Rebuild All: 1 succeeded, 1 failed, 0 skipped ==========

I have installed Qt to "C:\dev\Qt". I have the Qt Visual Studio addon, which i think should set the QtDir variable itself, and the project's library directories is set to "$(QtDir)\lib;$(LibraryPath)". I've also added "qtmaind.lib" to the list of additional dependencies.

Below is the linker command line:

/OUT:"C:\dev\projects\Window Detective\src\..\Window Detective.exe" /VERBOSE /NOLOGO "Psapi.lib" "qtmaind.lib" "Qt5Cored.lib" "Qt5Guid.lib" "Qt5Widgetsd.lib" "Qt5Xmld.lib" "kernel32.lib" "user32.lib" "gdi32.lib" "winspool.lib" "comdlg32.lib" "advapi32.lib" "shell32.lib" "ole32.lib" "oleaut32.lib" "uuid.lib" "odbc32.lib" "odbccp32.lib" "C:\dev\projects\Window Detective\src\hook\Debug\WD_Hook.lib" /MANIFEST /ManifestFile:"Debug\obj\Window Detective.exe.intermediate.manifest" /ALLOWISOLATION /MANIFESTUAC:"level='asInvoker' uiAccess='false'" /DEBUG /PDB:"C:\dev\projects\Window Detective\src\Debug\Window Detective.pdb" /SUBSYSTEM:WINDOWS /PGD:"C:\dev\projects\Window Detective\Window Detective.pgd" /TLBID:1 /DYNAMICBASE /NXCOMPAT /MACHINE:X86 /ERRORREPORT:QUEUE

As you can see, the library is mentioned there, and it definitely exists on disk, so i cannot see why the linker cannot find it.

xtal256
3rd January 2014, 00:16
Just to mention, i get the same problem when compiling in release mode - it cannot find "qtmain.lib".

xtal256
5th January 2014, 11:20
After reading some similar posts, i thought i might need to build Qt. I'm looking at Installing Qt for Windows (http://qt-project.org/doc/qt-5.1/qtdoc/install-win.html), but i'm not quite sure what options i want and where to install it to.
I already have Qt "installed" at C:\dev\Qt, where i see the following directory structure:
C:\dev\Qt
----5.1.0
--------msvc2010_opengl
------------bin
------------doc
------------examples
------------imports
------------include
------------lib
------------mkspecs
------------phrasebooks
------------plugins
------------qml
------------translations
--------src
------------qtactiveqt
------------qtbase
------------qtdeclarative
------------qtdoc
------------qtgraphicaleffects
------------qtimageformats
------------...
----Licenses
----Tools
----vcredist
----VSAddin

So if i ran "configure.exe", would i need to specify "C:\dev\Qt\5.1.0\msvc2010_opengl\" as the location, or just "C:\dev\Qt\5.1.0\" or what?
I thought i installed the pre-build package, so i don't even know if i need to run configure.

EDIT: Sorry for the crappy formatting on the directory listing, the forum collapses spaces (and turns no-break spaces into asterisks).

xtal256
8th January 2014, 00:26
hello? anyone?

ChrisW67
8th January 2014, 03:19
The linker does not find qtmaind.lib because whatever search path the linker is using does not include the Qt lib folder. I cannot see any reference to a library search path in your linker command. Given your claimed library directories I would start by hard coding rather than relying on a magic QtDir environment variable.

I do not have or use Visual Studio or the Qt Plugin so I cannot tell you how that should normally function.

xtal256
9th January 2014, 00:35
... I cannot see any reference to a library search path in your linker command....

Hmm, good point. I'll try and find out why that is.
Actually, i wasn't even aware that you could set the library search path. I've always just given the file names in the "Additional Dependencies" list, not their full path.
When I just gave the full path to all the Qt lib files, and the build succeeded. So at least that works. But i don't recall having to do that in the past.

d_stranz
9th January 2014, 21:29
Look in the property pages for your project (right click on the project in the VS Solution Explorer, select Properties). Expand the Linker section, and on the first page (General), you will see an "Additional Library Directories" property. If you click the "..." button on the right, it will display a dialog where you can enter the paths to the directories that contain non-default libraries. You can use environment variables as part of the path specification (like $(QTDIR)\lib) or relative paths (like ..\..\lib).

If you do this, you do not have to put full path names on each individual library in the Additional Dependencies list.

As you have no doubt noticed, the directory layout for the Qt installation changed dramatically between 4.8 and 5.x. Also be aware that when you deploy your app, things have changed there, too. The Windows dependencies are now in a DLL, and that DLL must be placed in a specific subdirectory relative to your executable and all the other Qt DLLs.

xtal256
10th January 2014, 09:48
Look in the property pages for your project (right click on the project in the VS Solution Explorer, select Properties). Expand the Linker section, and on the first page (General), you will see an "Additional Library Directories" property. If you click the "..." button on the right, it will display a dialog where you can enter the paths to the directories that contain non-default libraries. You can use environment variables as part of the path specification (like $(QTDIR)\lib) or relative paths (like ..\..\lib).

If you do this, you do not have to put full path names on each individual library in the Additional Dependencies list.
Thanks mate, that's exactly what i was looking for. I probably never noticed it before because i only had to do it once on my old computer.