2
votes

I currently have a problem with a C++ project I have. I need some tools provided with C++11 but when I want to compile with a Makefile, I have the error :

error This file requires compiler and library support for the ISO C++ 2011 standard. This support is currently experimental, and must be enabled with the -std=c++11 or -std=gnu++11 compiler options.

Here is my Makefile :

.PHONY: clean, mrproper

# var
CXX = g++
EXEC = tablut
LDFLAGS = 
CXXFLAGS = -std=c++11 -Wall -Wextra 
SRC= partie.cpp pawn.cpp playground.cpp
OBJ= $(SRC:.c=.o)

# commands
    all: $(EXEC)

tablut: $(OBJ)
    $(CXX) -o tablut $(OBJ) $(LDFLAGS)

%.o: %.cpp
    $(CXX) -o $@ -c $< $(CXXFLAGS) 

clean:
    rm -rf *.o

mrproper: clean
    rm -rf tablut

The funny thing is that my code compile if I enter the command g++ -c std=c++11 ...

What did I do wrong ?

NB : I tried with the flags -std=c++11, -std=c++0x and -std=gnu++11

1
Could you include the output from running make? - Bill Lynch
How comes it even works with this OBJ= $(SRC:.c=.o)??? It should be OBJ= $(SRC:.cpp=.o) - Alex Lop.
@AlexLop.: Because the only rule that fires is tablut because $(OBJ) == $(SRC). - Bill Lynch
@BillLynch Right! Good catch. Please add to your answer this explanation and show the actual compilation line which is being executed (and that it doesn't contain -std=c++11) - Alex Lop.

1 Answers

6
votes

You have the rule:

OBJ= $(SRC:.c=.o)

Which means that $(OBJ) ends up being:

OBJ= partie.cpp pawn.cpp playground.cpp

Because none of them match .c. You probably mean to write:

OBJ= $(SRC:.cpp=.o)

With that fix, running make produces:

$ make
g++ -o partie.o -c partie.cpp -std=c++11 -Wall -Wextra 
g++ -o pawn.o -c pawn.cpp -std=c++11 -Wall -Wextra 
g++ -o playground.o -c playground.cpp -std=c++11 -Wall -Wextra 
g++ -o tablut partie.o pawn.o playground.o 

Which is probably what you wanted.