error: C2057: expected constant expression
-
wrote on 25 Mar 2018, 15:32 last edited by Dr. No
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 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?
EDIT
Complete error message (the error is the same, with another Qt version I've tried, to see if anything changes):
C:\Qt-MSVC\Qt5.5.0\5.5\msvc2013\include\QtCore\qmetatype.h:944: see
reference to class template instantiation
'QtMetaTypePrivate::CapabilitiesImpl<QList<QVariant>,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<T>' 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<QVariantList>(const
T *)' being compiled with [
T=QVariantList ] -
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 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?
EDIT
Complete error message (the error is the same, with another Qt version I've tried, to see if anything changes):
C:\Qt-MSVC\Qt5.5.0\5.5\msvc2013\include\QtCore\qmetatype.h:944: see
reference to class template instantiation
'QtMetaTypePrivate::CapabilitiesImpl<QList<QVariant>,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<T>' 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<QVariantList>(const
T *)' being compiled with [
T=QVariantList ]That piece of code is quite correct. What is the complete error (with paths, lines and such)?
-
That piece of code is quite correct. What is the complete error (with paths, lines and such)?
wrote on 25 Mar 2018, 20:41 last edited by@kshegunov check out the post update
-
That piece of code is quite correct. What is the complete error (with paths, lines and such)?
wrote on 25 Mar 2018, 20:56 last edited by@kshegunov cl is this compiler:
C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.12.25827\bin\Hostx86\x86\cl.exe
is this the correct one, meant to be used with Qt 5.7.1? -
@kshegunov cl is this compiler:
C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.12.25827\bin\Hostx86\x86\cl.exe
is this the correct one, meant to be used with Qt 5.7.1?wrote on 25 Mar 2018, 23:37 last edited by kenchan@Dr.-No
I see reference to 2 Qt versions in your post Qt 5.7.1 in your text and Qt 5.5.0 ???
if you look here you will see that Qt 5.5 does not support the Vs 2017 compiler yet same for Qt. 5.7.1. maybe this is the issue?
If you use the Vs 2017 IDE maybe you can set set the target to a lower one if you have that one installed, don't know if you can do that using Qt Creator to build though. -
@Dr.-No
I see reference to 2 Qt versions in your post Qt 5.7.1 in your text and Qt 5.5.0 ???
if you look here you will see that Qt 5.5 does not support the Vs 2017 compiler yet same for Qt. 5.7.1. maybe this is the issue?
If you use the Vs 2017 IDE maybe you can set set the target to a lower one if you have that one installed, don't know if you can do that using Qt Creator to build though.wrote on 26 Mar 2018, 02:02 last edited by@kenchan I've tried a older version, 5.5.0 just to see if it could work. The error messages edited on my post (part of update) I copied from there. Hence the two diferente versions. But it did not work with either version and result in same error.
-
@kenchan I've tried a older version, 5.5.0 just to see if it could work. The error messages edited on my post (part of update) I copied from there. Hence the two diferente versions. But it did not work with either version and result in same error.
-
@Dr.-No well yes, but the higher compiler version might still be the issue in both cases.
if you scroll to the bottom of the linked page i gave you it shows the compatible tools for each Qt 5 version.wrote on 26 Mar 2018, 16:08 last edited by@kenchan So for Qt 5.7.1, the cl is Windows-Windows_10-x86-MSVC2015 I must use this visual studio 2015, right?
I've tried it already, download a 6gb isntallation and change my bat to the following:
call "C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\vcvarsall.bat" x86 "C:\Qt-MSVC\Qt5.7.1\Tools\QtCreator\bin\qtcreator.exe" and I get the same error...
-
@kenchan So for Qt 5.7.1, the cl is Windows-Windows_10-x86-MSVC2015 I must use this visual studio 2015, right?
I've tried it already, download a 6gb isntallation and change my bat to the following:
call "C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\vcvarsall.bat" x86 "C:\Qt-MSVC\Qt5.7.1\Tools\QtCreator\bin\qtcreator.exe" and I get the same error...
I think you're doing the thing backwards.
See what visual studio you already have (from the first post it seems VS2017-C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\...
), then from the Qt maintenance tool select a Qt version that provides you a binary distribution for that compiler, i.e. Qt >= 5.9 msvc2017-x86 and install it, possibly install the 64 bit binaries msvc2017-x86_x64 as well.
Then start Qt Creator (no need forcall ....
) and configure the kit for that Qt version and this compiler.
To get the debugger you will also need to install CDB from MS debugging tools package. -
I think you're doing the thing backwards.
See what visual studio you already have (from the first post it seems VS2017-C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\...
), then from the Qt maintenance tool select a Qt version that provides you a binary distribution for that compiler, i.e. Qt >= 5.9 msvc2017-x86 and install it, possibly install the 64 bit binaries msvc2017-x86_x64 as well.
Then start Qt Creator (no need forcall ....
) and configure the kit for that Qt version and this compiler.
To get the debugger you will also need to install CDB from MS debugging tools package.wrote on 26 Mar 2018, 19:02 last edited by@kshegunov I had VS 2017 instealled already before I need to use MSVC++ compiler with Qt. I was using mingw before but I needed to switch to MSVC++ because I have to use a debugging library that only supports MSVC++ debugg symbols. So I installed Qt with MSVC++ when I went to compile, that error begun. I use call to call the vcvarsall.bat file within my batch script, without the bat doesn't work.
-
@kshegunov I had VS 2017 instealled already before I need to use MSVC++ compiler with Qt. I was using mingw before but I needed to switch to MSVC++ because I have to use a debugging library that only supports MSVC++ debugg symbols. So I installed Qt with MSVC++ when I went to compile, that error begun. I use call to call the vcvarsall.bat file within my batch script, without the bat doesn't work.
@Dr.-No said in error: C2057: expected constant expression:
So I installed Qt with MSVC++
Please explain exactly what you did. There's no Qt with MSVC, there're a number of distributions of the Qt library compiled with different versions of the MS compiler, and what compiler you have will govern which exact distribution of Qt you will need.
I use call to call the vcvarsall.bat file within my batch script, without the bat doesn't work.
You can start Qt Creator without ever needing to have an installed compiler. I don't understand why you call the
bat
script before starting the IDE. What you need is, as I wrote, to configure the toolchain for your compiler, not start the IDE with the visual studio environment. -
wrote on 26 Mar 2018, 20:19 last edited byThis post is deleted!
-
@Dr.-No said in error: C2057: expected constant expression:
So I installed Qt with MSVC++
Please explain exactly what you did. There's no Qt with MSVC, there're a number of distributions of the Qt library compiled with different versions of the MS compiler, and what compiler you have will govern which exact distribution of Qt you will need.
I use call to call the vcvarsall.bat file within my batch script, without the bat doesn't work.
You can start Qt Creator without ever needing to have an installed compiler. I don't understand why you call the
bat
script before starting the IDE. What you need is, as I wrote, to configure the toolchain for your compiler, not start the IDE with the visual studio environment.wrote on 26 Mar 2018, 20:46 last edited by@kshegunov I downloaded the Qt Creator from this link, installed, opened my project but when I went to compile I got a cl not found error. So I search on google about the error and found that I should run vcvarsall.bat x86 to set up the needed varialbles. I did that and went to compile again, this time, the cl error was gone but then I got the error, title of this thread. Does make sense to configure the toolchain within the IDE but it didn't work. In fact, I saw alot of people running that script before using Qt Creator IDE, hence the need of this bat.
-
@kshegunov I downloaded the Qt Creator from this link, installed, opened my project but when I went to compile I got a cl not found error. So I search on google about the error and found that I should run vcvarsall.bat x86 to set up the needed varialbles. I did that and went to compile again, this time, the cl error was gone but then I got the error, title of this thread. Does make sense to configure the toolchain within the IDE but it didn't work. In fact, I saw alot of people running that script before using Qt Creator IDE, hence the need of this bat.
@Dr.-No said in error: C2057: expected constant expression:
In fact, I saw alot of people running that script before using Qt Creator IDE, hence the need of this bat.
I haven't seen or done that, it may work or not, can't say. What I usually do is follow the Qt Creator manual on configuring the compilers and just put the VC init script in the proper box, that is if creator has failed to detect the compiler automatically ...
-
@Dr.-No said in error: C2057: expected constant expression:
In fact, I saw alot of people running that script before using Qt Creator IDE, hence the need of this bat.
I haven't seen or done that, it may work or not, can't say. What I usually do is follow the Qt Creator manual on configuring the compilers and just put the VC init script in the proper box, that is if creator has failed to detect the compiler automatically ...
wrote on 27 Mar 2018, 01:12 last edited by@kshegunov Qt doesn't fail to detect the compiler but it give the cl command not found error, like this: https://stackoverflow.com/questions/8800361/cl-is-not-recognized-as-an-internal-or-external-command
The only thing which makes the error go away was that VS batch script to set up the proper paths in the system environment's variables.
-
@kshegunov Qt doesn't fail to detect the compiler but it give the cl command not found error, like this: https://stackoverflow.com/questions/8800361/cl-is-not-recognized-as-an-internal-or-external-command
The only thing which makes the error go away was that VS batch script to set up the proper paths in the system environment's variables.
-
@kenchan No. I'm with same error... I solved the cl error before create this thread. Once this compiled, I got expected constant expression error.
wrote on 27 Mar 2018, 02:10 last edited by@Dr.-No Oh dear :-(.
OK so just to clarify where you are now when you get this error...
which Qt are you now building against?
which version of Visual Studio are you now building with?
are you using the QT Creator IDE to build the project?
are you using Visual Studio IDE to build the project? -
@Dr.-No Oh dear :-(.
OK so just to clarify where you are now when you get this error...
which Qt are you now building against?
which version of Visual Studio are you now building with?
are you using the QT Creator IDE to build the project?
are you using Visual Studio IDE to build the project?wrote on 27 Mar 2018, 02:16 last edited by@kenchan This is really bad, I have no idea why I'm getting this error. :( I'm downloading 5.10.1 to see if it works. Hope it's something has been fixed.
which Qt are you now building against?
Qt creator 4.2.0 and Qt 5.7.1
which version of Visual Studio are you now building with?
Visual studio community 2017
are you using the QT Creator IDE to build the project?
yes, as mentioned, version 4.2.0
are you using Visual Studio IDE to build the project?
nope... as it Qt project (written using mingw) I have only used Qt creator IDE.
-
@kenchan This is really bad, I have no idea why I'm getting this error. :( I'm downloading 5.10.1 to see if it works. Hope it's something has been fixed.
which Qt are you now building against?
Qt creator 4.2.0 and Qt 5.7.1
which version of Visual Studio are you now building with?
Visual studio community 2017
are you using the QT Creator IDE to build the project?
yes, as mentioned, version 4.2.0
are you using Visual Studio IDE to build the project?
nope... as it Qt project (written using mingw) I have only used Qt creator IDE.
1/28