funwound
funwound

Reputation: 11

qwt examples fail to build with linker error on Windows with MSVC (LNK2019)

I have QT 6.2.2 installed on Windows 10 and am trying to build qwt 6.2.0. Compilation via MSVC of the qwt library is successful but nmake outputs linker errors when compiling the qwt examples. I am attempting to compile all of qwt via the QT MSVC command prompt by loading vcvars from MSVC, running qmake, then running nmake as instructed here (https://qwt.sourceforge.io/qwtinstall.html#BUILDSUBSECTION).

The output of nmake is here:

Microsoft (R) Program Maintenance Utility Version 14.30.30706.0
Copyright (C) Microsoft Corporation.  All rights reserved.

linking ..\bin\animation.exe
MSVCRT.lib(exe_winmain.obj) : error LNK2019: unresolved external symbol WinMain referenced in function "int __cdecl __scrt_common_main_seh(void)" (?__scrt_common_main_seh@@YAHXZ)
..\bin\animation.exe : fatal error LNK1120: 1 unresolved externals
NMAKE : fatal error U1077: 'echo' : return code '0x460'
Stop.
NMAKE : fatal error U1077: '"C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.30.30705\bin\HostX64\x64\nmake.exe"' : return code '0x2'
Stop.
NMAKE : fatal error U1077: 'cd' : return code '0x2'
Stop.
NMAKE : fatal error U1077: 'cd' : return code '0x2'
Stop.

I've tried this on two different windows 10 machines and run into the same problem on both machines.

Upvotes: 1

Views: 1058

Answers (2)

tinman
tinman

Reputation: 6608

Edit: the solution I originally posted below is based on the older code for the 6.2.0 release (as per the question), which was released on the 18th July 2021. The source code for the 6.2 branch and develop branch seems to have been fixed in this regard as of commit 9c2b5cef0b7ad2f9c6a8aade6802e2bc15a80e2c, on the 8th May 2023. So a simpler solution might be just to get the latest source code rather than use the pre-packaged 6.2.0 release.


This seems to be related to the QtEntryPoint library, which is used on Windows

to allow a developer to write a crossplatform main

In order to fix this in the case of the Qwt examples I added the following to the end of the "examples/examples.pri" file.

win32 {
    CONFIG(debug, debug|release) {
        LIBS += -l$$[QT_HOST_LIBS]\Qt6EntryPointd
    } else {
        LIBS += -l$$[QT_HOST_LIBS]\Qt6EntryPoint
    }
    LIBS += -lshell32
}

The examples build "OK" after this and you do not need to modify the makefiles each time you regenerate them. I say OK, the executables seem to work, but I don't know whether there is anything else missing from the standard libraries that would get linked for an executable, or collisions between libraries that would only need to be linked into a library.

Speculation on my part but it could be to do with qmake being confiugured to build the Qwt library (which would not need an entry point) and the examples (which would need it), all using common qmake configuration files. Qmake is meant to include this stuff automatically for an executable (and it does if you start a brand new executable project), so I am assuming it is some interaction of configuration.

Upvotes: 0

ToreSupra
ToreSupra

Reputation: 11

Ran into the exact same problem yesterday. Found a solution (probably not the cleanest oen)

Edit every Makefile.Debug & Makefile.Release for the examples that raise that error. at the end of the LFLAGS line, add "/ENTRY:mainCRTStartup".

Solution comes from: error LNK2019: unresolved external symbol _WinMain@16 referenced in function ___tmainCRTStartup

There is probably a smarter solution than editing so many files...

Upvotes: 1

Related Questions