简体   繁体   中英

error: C2057: expected constant expression

I'm trying to build a project orignally made on top of mingw but now we need to switch to MSVC++ (because a specific debugging library only supports that) but to my surprise, compiling that code even on new C++ version/Qt result in the error:

error: C2057: expected constant expression

The error is not part of my own source code rather Qt itself, from qmetatype.h header, so I have no idea how fix. I assumed it was missing C++11 flag, so I added CONFIG += c++11 nothing changed. Then I tried to more specific and added QMAKE_CXXFLAGS += /std:c++14 to .pro file. Same error. The line of error is:

struct CapabilitiesImpl<T, std::random_access_iterator_tag>
{ enum { IteratorCapabilities = RandomAccessCapability | BiDirectionalCapability | ForwardCapability }; };

NOTE: Since I was getting cl not found error, I do star the Qt creator from a qt.bat file like this:

call "C:\Program Files (x86)\Microsoft Visual
Studio\2017\Community\VC\Auxiliary\Build\vcvarsall.bat" x86
"C:\Qt-MSVC\Qt5.7.1\Tools\QtCreator\bin\qtcreator.exe"

How can I fix that?

UPDATE

I've tried to use an older version to see if it makes any differentce, which didn't but I got more context about the error:

C:\\Qt-MSVC\\Qt5.5.0\\5.5\\msvc2013\\include\\QtCore\\qmetatype.h:944: see reference to class template instantiation 'QtMetaTypePrivate::CapabilitiesImpl,std::random_access_iterator_tag>' being compiled C:\\Qt-MSVC\\Qt5.5.0\\5.5\\msvc2013\\include\\QtCore\\qmetatype.h:1015: see reference to class template instantiation 'QtMetaTypePrivate::ContainerAPI' being compiled with [ T=QVariantList ] C:\\Qt-MSVC\\Qt5.5.0\\5.5\\msvc2013\\include\\QtCore\\qvariant.h:711: see reference to function template instantiation 'QtMetaTypePrivate::QSequentialIterableImpl::QSequentialIterableImpl(const T *)' being compiled with [ T=QVariantList ]

You do need to define the MSVC -specific environment variables when you are make something in QT using the MSVC compiler. Therefore, running vcvarsall.bat is mandatory, unless you manually define those environment variables yourself.

VCVarsall.bat is Visual Studio Command Prompt tool in Visual Studio. It's the tool that allows you to set various options for the integrated development environment (IDE) as well as build, debug, and deploy projects from the command line.

Source

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM