我正在尝试构建最初在mingw之上制作的项目,但现在我们需要切换到MSVC++(因为特定的调试库仅支持该功能),但令我惊讶的是,即使在新的C++版本/Qt上编译该代码也会导致错误:
error: C2057: expected constant expression
错误不是我自己的源代码的一部分,而是
qmetatype.h
header 中的Qt本身,所以我不知道如何解决。我以为它缺少C++ 11标志,所以我添加了CONFIG += c++11
并没有改变。然后,我尝试更具体,并在QMAKE_CXXFLAGS += /std:c++14
文件中添加了.pro
。同样的错误。错误行是:struct CapabilitiesImpl<T, std::random_access_iterator_tag>
{ enum { IteratorCapabilities = RandomAccessCapability | BiDirectionalCapability | ForwardCapability }; };
注意:由于出现cl找不到错误,因此我从 qt.bat 文件中为Qt创建者加注星标,如下所示:
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"
我该如何解决?
更新
我尝试使用一个较旧的版本来查看它是否具有任何区别,但没有,但是我得到了有关该错误的更多信息:
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 ]
最佳答案
使用MSVC编译器在QT中进行某些操作时,确实需要定义特定于MSVC的环境变量。因此,除非您自己手动定义这些环境变量,否则必须运行vcvarsall.bat
。
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.
关于c++ - 错误: C2057: expected constant expression,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49477421/