constexpr not declared in this scope

298 views
Skip to first unread message

JS

unread,
Sep 3, 2017, 9:45:10 PM9/3/17
to PPP-public
I have this error when I tried to run this program
#include "../std_lib_facilities.h"
int main()
{
         
constexpr double cm_per_inch = 2.54;         // number of centimeters in
                                                                                 
// an inch
         
double length = 1;                                         // length in inches or
                                                                                 
// centimeters
         
char unit = ' ';                                                 // a space is not a unit
          cout
<< "Please enter a length followed by a unit (c or i):\n";
          cin
>> length >> unit;

         
if (unit == 'i')
                    cout
<< length << "in == " << cm_per_inch*length << "cm\n";
         
else if (unit == 'c')
                    cout
<< length << "cm == " << length/cm_per_inch << "in\n";
         
else
                    cout
<< "Sorry, I don't know a unit called '" << unit << "'\n";
}

Here is the detailed log
C:\WINDOWS\system32\cmd.exe /C C:/MinGW64/mingw32/bin/mingw32-make.exe -j2 SHELL=cmd.exe -e -f  Makefile
"----------Building project:[ ex4 - Debug ]----------"
mingw32
-make.exe[1]: Entering directory 'C:/Users/User_1/Documents/Coding/ex4'
C
:/MinGW64/mingw32/bin/g++.exe  -c  "C:/Users/User_1/Documents/Coding/ex4/main.cpp" -g -O0 -Wall  -o ./Debug/main.cpp.o -I. -I.
In file included from C:/MinGW64/mingw32/i686-w64-mingw32/include/c++/ext/hash_map:60:0,
                 
from C:/Users/User_1/Documents/Coding/std_lib_facilities.h:34,
                 
from C:/Users/User_1/Documents/Coding/ex4/main.cpp:4:
C
:/MinGW64/mingw32/i686-w64-mingw32/include/c++/backward/backward_warning.h:32:2: warning: #warning This file includes at least one deprecated or antiquated header which may be removed without further notice at a future date. Please use a non-deprecated interface with equivalent functionality instead. For a listing of replacement headers and interfaces, consult the file backward_warning.h. To disable this warning use -Wno-deprecated. [-Wcpp]
 
#warning \
 
^
C
:/Users/User_1/Documents/Coding/ex4/main.cpp:7:11: warning: identifier 'constexpr' is a keyword in C++11 [-Wc++0x-compat]
           
constexpr double cm_per_inch = 2.54;         // number of centimeters in
           
^
C
:/Users/User_1/Documents/Coding/ex4/main.cpp: In function 'int main()':
C
:/Users/User_1/Documents/Coding/ex4/main.cpp:7:11: error: 'constexpr' was not declared in this scope
C
:/Users/User_1/Documents/Coding/ex4/main.cpp:16:51: error: 'cm_per_inch' was not declared in this scope
                     cout
<< length << "in == " << cm_per_inch*length << "cm\n";
                                                   
^
C
:/Users/User_1/Documents/Coding/ex4/main.cpp:18:58: error: 'cm_per_inch' was not declared in this scope
                     cout
<< length << "cm == " << length/cm_per_inch << "in\n";
                                                         
^
mingw32
-make.exe[1]: *** [Debug/main.cpp.o] Error 1
ex4
.mk:97: recipe for target 'Debug/main.cpp.o' failed
mingw32
-make.exe[1]: Leaving directory 'C:/Users/User_1/Documents/Coding/ex4'
mingw32
-make.exe: *** [All] Error 2
Makefile:4: recipe for target 'All' failed
====4 errors, 3 warnings====

I am using mingw64 gcc version 5.4.0, I think that my compiler doesn't support constexpr. How can I fix this? Thanks

Christiano

unread,
Sep 3, 2017, 11:13:41 PM9/3/17
to PPP-public
You are using Codelite.
Codelite >> Project settings >> Compiler >> Compiler options >> add ;-std=c++11
Preferably you should use command line before using an IDE because when a error like that happens you will know the solution.

Example:
C:/MinGW64/mingw32/bin/g++.exe  -c  "C:/Users/User_1/Documents/Coding/ex4/main.cpp" -g -O0 -Wall  -o ./Debug/main.cpp.o -I. -I.


-c = create object
-g = debug option
-O0 = optimization
-Wall = see all warnings
-o = name of output
-I = include directory

With modifications the Codelite will do:

C:/MinGW64/mingw32/bin/g++.exe -std=c++11 -c  "C:/Users/User_1/Documents/Coding/ex4/main.cpp" -g -O0 -Wall  -o ./Debug/main.cpp.o -I. -I.

If your compiler supports, you can add -std=c++14 instead.
Without -std=c++11/-std=c++14 almost all code in the book will not work.

JS

unread,
Sep 4, 2017, 3:22:06 AM9/4/17
to PPP-public

C:/MinGW64/mingw32/bin/g++.exe -std=c++11 -c  "C:/Users/User_1/Documents/Coding/ex4/main.cpp" -g -O0 -Wall  -o ./Debug/main.cpp.o -I. -I.
I pasted that into command prompt and it got this

In file included from C:/MinGW64/mingw32/i686-w64-mingw32/include/c++/ext/hash_map:60:0,
                 
from C:/Users/User_1/Documents/Coding/std_lib_facilities.h:34,
                 
from C:/Users/User_1/Documents/Coding/ex4/main.cpp:4:
C
:/MinGW64/mingw32/i686-w64-mingw32/include/c++/backward/backward_warning.h:32:2: warning: #warning This file includes at least one deprecated or antiquated header which may be removed without further notice at a future date. Please use a non-deprecated interface with equivalent functionality instead. For a listing of replacement headers and interfaces, consult the file backward_warning.h. To disable this warning use -Wno-deprecated. [-Wcpp]
 
#warning \
 
^
In file included from C:/MinGW64/mingw32/i686-w64-mingw32/include/c++/locale:41:0,
                 
from C:/MinGW64/mingw32/i686-w64-mingw32/include/c++/iomanip:43,
                 
from C:/Users/User_1/Documents/Coding/std_lib_facilities.h:212,
                 
from C:/Users/User_1/Documents/Coding/ex4/main.cpp:4:
C
:/MinGW64/mingw32/i686-w64-mingw32/include/c++/bits/locale_facets_nonio.h:1971:5: error: template-id 'do_get<>' for 'String std::__cxx11::messages<char>::do_get(std::messages_base::catalog, int, int, const String&) const' does not match any template declaration
     messages
<char>::do_get(catalog, int, int, const string&) const;
     
^
C
:/MinGW64/mingw32/i686-w64-mingw32/include/c++/bits/locale_facets_nonio.h:1971:62: note: saw 1 'template<>', need 2 for specializing a member function template
     messages
<char>::do_get(catalog, int, int, const string&) const;
                                                             
^
I have no idea what it means. I looked into ./Debug/main.cpp.o for output and expected an exe file but its not there? I don't really know how to use the command line. There are so many things I don't know yet, so all of these seems very confusing. Next thing I put
-std=c++11 into Codelite and this pops up.

C:\WINDOWS\system32\cmd.exe /C C:/MinGW64/mingw32/bin/mingw32-make.exe -j2 SHELL=cmd.exe -e -f  Makefile
"----------Building project:[ ex4 - Debug ]----------"
mingw32
-make.exe[1]: Entering directory 'C:/Users/User_1/Documents/Coding/ex4'

C
:/MinGW64/mingw32/bin/g++.exe  -c  "C:/Users/User_1/Documents/Coding/ex4/main.cpp" -g -O0 -std=c++11 -Wall  -o ./Debug/main.cpp.o -I. -I.

In file included from C:/MinGW64/mingw32/i686-w64-mingw32/include/c++/ext/hash_map:60:0,
                 
from C:/Users/User_1/Documents/Coding/std_lib_facilities.h:34,
                 
from C:/Users/User_1/Documents/Coding/ex4/main.cpp:4:
C
:/MinGW64/mingw32/i686-w64-mingw32/include/c++/backward/backward_warning.h:32:2: warning: #warning This file includes at least one deprecated or antiquated header which may be removed without further notice at a future date. Please use a non-deprecated interface with equivalent functionality instead. For a listing of replacement headers and interfaces, consult the file backward_warning.h. To disable this warning use -Wno-deprecated. [-Wcpp]
 
#warning \
 
^
In file included from C:/MinGW64/mingw32/i686-w64-mingw32/include/c++/locale:41:0,
                 
from C:/MinGW64/mingw32/i686-w64-mingw32/include/c++/iomanip:43,
                 
from C:/Users/User_1/Documents/Coding/std_lib_facilities.h:212,
                 
from C:/Users/User_1/Documents/Coding/ex4/main.cpp:4:
C
:/MinGW64/mingw32/i686-w64-mingw32/include/c++/bits/locale_facets_nonio.h:1971:5: error: template-id 'do_get<>' for 'String std::__cxx11::messages<char>::do_get(std::messages_base::catalog, int, int, const String&) const' does not match any template declaration
     messages
<char>::do_get(catalog, int, int, const string&) const;
     
^
C
:/MinGW64/mingw32/i686-w64-mingw32/include/c++/bits/locale_facets_nonio.h:1971:62: note: saw 1 'template<>', need 2 for specializing a member function template
     messages
<char>::do_get(catalog, int, int, const string&) const;

                                                             
^
mingw32
-make.exe[1]: *** [Debug/main.cpp.o] Error 1
ex4
.mk:97: recipe for target 'Debug/main.cpp.o' failed
mingw32
-make.exe[1]: Leaving directory 'C:/Users/User_1/Documents/Coding/ex4'
mingw32
-make.exe: *** [All] Error 2
Makefile:4: recipe for target 'All' failed
====2 errors, 4 warnings====
You got idea what is happening ? Also where can I learn more about the command line?


Christiano

unread,
Sep 4, 2017, 3:55:34 AM9/4/17
to PPP-public

JS

unread,
Sep 4, 2017, 4:15:29 AM9/4/17
to PPP-public
Looks like it's fixed, thanks for helping again. I got a few questions though.

What was the difference between the first and second std_lib_facilities?
I am interested in using the command line, how can I start? Or should I stick to Codelite?

Christiano

unread,
Sep 4, 2017, 6:03:02 AM9/4/17
to PPP-public
The first had :
#define string String
It is a hack in order to substitute standard string by customized string (String) which has range check.
This substitution + #include<iomanip> = disaster.

the second doesn't have #define string String.
Message has been deleted

JS

unread,
Sep 4, 2017, 7:15:58 AM9/4/17
to PPP-public
Okay thanks man, in the mean time I'll stick with IDE

Daniel Elbro

unread,
Jun 17, 2019, 9:21:19 AM6/17/19
to PPP-public
Your second link (about compiling the GUI stuff) is dead, do you know any other way to get there?
Reply all
Reply to author
Forward
0 new messages