1

Using Qt 5.15.0 in Visual Studio 2019 with the Qt VS Tools extension installed.

#include <QVector>
int main()
{
    QVector<int> myList;
    return 0;
}

The above minimal program builds in RELEASE mode, but gives link errors in DEBUG mode:

error LNK2019: unresolved external symbol __imp__invalid_parameter referenced in function "void __cdecl std::_Load_barrier(enum std::memory_order)"
error LNK2019: unresolved external symbol __imp__CrtDbgReport referenced in function "void __cdecl std::_Load_barrier(enum std::memory_order)"
fatal error LNK1120: 2 unresolved externals

I stumbled on this question which gave me the hint about the build configuration. In Project Properties > Qt Project Settings, I was not able to identify the setting that needs to change.

How do I resolve this issue?

Update 1

Some additional configuration details (suggested in a comment):

  • Simple Visual Studio .sln file (no CMake) which loads a .vcxproj project
  • Qt was downloaded and is installed to C:\Qt

Update 2

Additional details from the Visual Studio project (.vcxproj) file based on a comment. This is how Qt is referenced for Debug/Release builds:

<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x64'" Label="QtSettings">
  <QtInstall>msvc2019_64</QtInstall>
  <QtModules>core</QtModules>
  <QtBuildConfig>debug</QtBuildConfig>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x64'" Label="QtSettings">
  <QtInstall>msvc2019_64</QtInstall>
  <QtModules>core</QtModules>
  <QtBuildConfig>release</QtBuildConfig>
</PropertyGroup>
AlainD
  • 5,413
  • 6
  • 45
  • 99
  • It's hard to say without seeing your project configuration, are you using Visual Studio project (.sln) or building with CMake? How are you linking Qt libraries, did you build or download them? – Kaldrr Jul 21 '20 at 09:20
  • @Kaldrr: Just a simple `.sln` which loads a `.vcxproj`. Qt was downloaded and is installed at C:\Tmp\Qt. Was testing Qt and have been able to use `QString`, `QDir`, and some other classes fine in both RELEASE and _DEBUG modes. `QVector` was the first one that did not link. – AlainD Jul 21 '20 at 09:22
  • It is not really related to your question, but I would like to mention that it is considered a very bad practice to have a `main` with `void` as return type in C++ (unless you are on an embedded system of course) as you will have no idea of how your program exited if it happens to crash. You may want to return `EXIT_SUCCESS` or `EXIT_FAILURE` defined in `stdio.h` or something similar. To quote Bjarne Stroustrup : > The definition void main() is not and never has been C++, nor has it even been C. https://en.cppreference.com/w/cpp/language/main_function – Erel Jul 21 '20 at 10:57
  • @Erel: Fair point, I just wanted a minimal example. I've updated the question accordingly. – AlainD Jul 21 '20 at 11:07
  • How does Qt project file look like? It must be yourProject.pro file. Does it have `QT += core` line? – Alexander V Jul 21 '20 at 14:29
  • @AlexanderV: I'm using Visual Studio with a `.vcxproj` file. I'll update the question with details about how Qt is referenced in there. – AlainD Jul 21 '20 at 14:55
  • @AlainD Try to create same project with Qt Creator in Windows and see if that works. Something went wrong with importing the Qt project. Then if it works in Qt Creator you will be able to re-import it to Visual Studio. Though, why, we can use Creator. – Alexander V Jul 21 '20 at 15:42
  • Can't reproduce as well, you could try building with diffrent Windows SDK maybe? – Kaldrr Jul 21 '20 at 16:57

0 Answers0