I suppose this question is asked in some other threads, I was getting the error while calling make: to_string is not declared in this scope. I found out I have to add c++11 in makefile. But I tried some options mentioned in several threads. Could you provide some solution here? Thanks
-
2can you post a minimal complete example please so that we can start to think about what might be wrong? – Richard Hodges Aug 12 '15 at 08:14
-
This is my makefile http://1drv.ms/1JTD6T6, I could not add all the contents due to space limit – naman arora Aug 12 '15 at 08:14
-
I presume you're using g++. This compiler is strong on standard-conformance for the core language, but weak on the standard library (takes long to catch up). Thus there is a distinct possibility that `to_string` is actually missing, depending on the version. Complementing this, Microsoft's compiler is weak on standard-conformance for the core language, but strong on the standard library. Perhaps due to efforts of STL. (That's a person, not the Standard Template Library: at Microsoft, STL maintains the STL). – Cheers and hth. - Alf Aug 12 '15 at 08:20
-
@namanarora: please do narrow your code down to a **minimal but complete example**. thank you. – Cheers and hth. - Alf Aug 12 '15 at 08:22
-
@Cheers and hth. - Alf Is this ok? I am not sure about minimal but complete example, these are the contents of the make file, other things are normal, probably here is some thing missing: CC=g++ LD=g++ CFLAGS=-c -g -O3 -finline-functions -fstack-protector – naman arora Aug 12 '15 at 08:23
-
And I also ran on Mac, it was working there – naman arora Aug 12 '15 at 08:27
1 Answers
Adding -std=c++11
to CFLAGS
will cause g++
to compile with the C++11 standard. Like this
CFLAGS=-std=c++11 -c -g -O3 -finline-functions -fstack-protector
However, as highlighted in comments the appropriate syntax for compiling C++ programs with a makefile
is to use a rule like this
$(CXX) $(CPPFLAGS) $(CXXFLAGS) -c
where your C++ files use the suffix .cc
[1]. Then you would add -std=c++11
to CXXFLAGS
. The difference between CPPFLAGS
and CXXFLAGS
is [2]
CPPFLAGS is supposed to be for flags for the C PreProcessor; CXXFLAGS is for flags for the C++ compiler.
This would require some rewrites within your makefile
, namely
CXX=g++
LD=g++
CXXFLAGS=-c -g -O3 -fstack-protector -I./Eigen
and rules from
$(CC) $(INCLUDE) $(CFLAGS) -c
to
$(CXX) $(CPPFLAGS) $(CXXFLAGS) -c
as above.
The $(INCLUDE)
can also be removed from your linking command ($(LD)
) as it is only needed during compile time. Your linking command can also be simplified to
ParEGOIteration13: ParEGOIteration13.o Utilities.o WeightVector.o SearchSpace.o DACE.o GeneticAlgorithm.o Matrix.o
$(CXX) $? -o $@
by using the automatic variables [3]
$?
expands to all of the prerequisites$@
expands to the name of the target
I'll let you work out how to use the automatic variables in your compilation rules.
Note: I've removed -finline-functions
as -O3
(and -O2
) turn it on by default with gcc.

- 6,089
- 11
- 42
- 47
-
-
In the `makefile` posted in the comments that would require much more significant changes. – IKavanagh Aug 12 '15 at 08:58
-
"much more significant change", you mean also changing `CC` to `CXX` ? The guy is learning things, doesn't hurt to give him full infos/advice while you're at it :) – Drax Aug 12 '15 at 09:00
-
@Drax I've updated the answer based on your comments. I think I've covered most of the basics to help the guy out now. – IKavanagh Aug 12 '15 at 09:37
-