Modification of the Makefile to support C ++ 11

I can compile a single file using gcc with the -std = C ++ 0x option. But I can not do this via makefile. Here is the set of flags in my makefile (which after you complain about C ++ 11 keywords):

MACHINE = $(shell echo `uname -s`-`uname -m` | sed "s/ //g") CCC = CC CCC = g++ CFLAGS = -O3 CFLAGS = -std=c++0x CFLAGS = -pg -D_DEBUG -g -c -Wall LFLAGS = -O LFLAGS = -pg -g 

What am I missing?

Edit : I changed it to the following, but I still get compilation errors that I don't get with gcc command line invocation.

 CXXFLAGS=-O3 -std=c++0x -pg -D_DEBUG -g -c -Wall 
+7
source share
3 answers

Thus, your makefile will use all your CFLAGS :

 CFLAGS=-O3 -std=c++0x -pg -D_DEBUG -g -c -Wall 

You override them with every declaration of "CFLAGS = ...".

In addition, it should be CXXFLAGS , not CFLAGS . CFLAGS for C. Applications

As @Florian Sowade said, you can use CFLAGS += -O3 -std.... (or CXXFLAGS ..) so that users can provide their own flags when doing make.

+12
source

You can save it in several lines, but you probably want to add rather than assign:

 # eg CFLAGS += -O3 CFLAGS += -std=c++0x CFLAGS += -pg -D_DEBUG -g -c -Wall 
+3
source

Where did you get this mess? This makefile was wrong long before you changed it for C ++ 11.

Let's start with the first line:

 MACHINE = $(shell echo `uname -s`-`uname -m` | sed "s/ //g") 

Try running the echo `uname -s`-`uname -m` and you will see that there are no spaces in it, so what's the point in the sed command?

Perhaps you want to:

 MACHINE = $(shell uname -s -m | sed "s/ /-/g") 

This only works for two processes (uname and sed), not four (two unames, echo and sed)

If you are using GNU make, this should be

 MACHINE := $(shell uname -s -m | sed "s/ /-/g") 

So, it starts only once.

 CCC = CC 

What is CC ?

 CCC = g++ 

Oh, it doesn't matter, you replaced the value anyway. Plain make variable for C ++ CXX

 CFLAGS = -O3 CFLAGS = -std=c++0x CFLAGS = -pg -D_DEBUG -g -c -Wall 

As others have pointed out, you install CFLAGS, then install it on something else, and then on something else. Only the last value will be saved.

 LFLAGS = -O LFLAGS = -pg -g 

The same and what is LFLAGS ? Do you mean LDFLAGS ?

A good way to debug makefiles is to create a landing page for printing the variables you set to verify that they have the expected values:

 print-vars: echo CFLAGS is $(CFLAGS) echo LDFLAGS is $(LDFLAGS) 
0
source

All Articles