Iramch Iramch - 1 year ago 88
C++ Question

CFLAGS not recognised in makefile

I'm complicating a small school assignment which uses lambda functions, so it needs the '-std=c++11' in the gcc call. However the output of the make file seems to show that it is not being added. I'm not having linking problems so there is no need to copy all the source here.

Here is my makefile:

CFLAGS= -std=c++11 -I. -Wall
DEPS = wordarray.h
OBJ = ayalajL03b.o wordarray.o

%.o: %.c $(DEPS)
$(CC) -c -o $@ $< $(CFLAGS)

L03b.out: $(OBJ)
$(CC) -o $@ $^ $(CFLAGS)

.PHONY: clean

rm -f -v *.o
rm -f -v *.out

Here is the output:

[user@server Lab03]$ make
g++ -c -o wordarray.o wordarray.cpp
wordarray.cpp:28:77: warning: lambda expressions only available with -std=c++11 or =gnu++11
counter([](char a)->bool{return !isvowel(a) && !isdigit(a) && isalpha(a);}, Worount].word);

Please help me understand what I'm doing wrong.

Answer Source

Your rule is

%.o: %.c $(DEPS)

but you are compiling a .cpp file.

The implicit make rule for .cpp source files will be used.

Either change your rule to

%.o: %.cpp $(DEPS)

Or set the CXXFLAGS variable used in the implicit rule.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download