3

I have an MFC C++ project, which builds and runs just fine with Visual Studio 2022 on Windows 10. The project doesn't use Qt at all. After I installed Qt 6.2.1 with vcpkg, project stopped building with this linker error:

1>Qt6EntryPoint.lib(qtentrypoint_win.cpp.obj) : error LNK2019: unresolved external symbol main referenced in function WinMain

Again, there is no usage of Qt6 in my project. Going to project's Configuration Properties and disabling Use Vcpkg makes it build again. What is going on here and how to fix it without disabling vcpkg?


I created a new C++ MFC App with VS project wizard and default settings. It builds fine with vcpkg enabled.


The only reasonable explanation I can offer is that many generations ago, older VS, older Windows, my project was using a few classes from Qt4 core for a while, which caused problems, so that functionality was removed. I continued to develop it on Windows without Qt installed. Is it possible that some reference to Qt is still lurking around? How to find it? I checked settings several times and couldn't find any.


I looked at the order of library search (/VERBOSE:Lib) and with vcpkg -> Use Autolink enabled, vcpkg folders are searched first. Is there a way to make the linker search system folders first?

Here is what's happening:

1>    Searching C:\src\vcpkg\installed\\x64-windows\lib\Qt6EntryPoint.lib:
1>      Found WinMain
1>        Referenced in msvcrt.lib(exe_winmain.obj)
1>        Loaded Qt6EntryPoint.lib(qtentrypoint_win.cpp.obj)

Excluding Qt6EntryPoint.lib with /NODEFAULTLIB:"Qt6EntryPoint.lib" has no effect. Is there another way to exclude it?

Paul Jurczak
  • 7,008
  • 3
  • 47
  • 72
  • 1
    But you do use Qt, you're linking it. What you probably didn't count on is that both MFC and Qt are frameworks that want to define the program's entrypoint, so they can initialize early enough. The linker picked Qt's WinMain(). Fixing it is a bit awkward, you'll have to link the MFC library first. IIRC, the link dependency is injected with #pragma lib, you have to name it explicitly. – Hans Passant Dec 08 '21 at 02:25
  • @HansPassant *But you do use Qt* No, I don't. The linker spuriously picks it up. I will look into #pragma lib or try to exclude Qt6EntryPoint.lib from the build. – Paul Jurczak Dec 08 '21 at 02:38

1 Answers1

3

This means you should open up an issue in vcpkg.
Qt6EntryPoint.lib needs to be moved into the /manual-link subfolder.
(I really hate the lazy MSBuild autolink/link everything feature of vcpkg.)

Alexander Neumann
  • 1,479
  • 8
  • 17
  • 1
    Thanks. I reported an issue: https://github.com/microsoft/vcpkg/issues/22072. It looks like they are going to fix it as you suggested. – Paul Jurczak Dec 20 '21 at 19:28