1

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:

CC=g++
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

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.

Iramch
  • 13
  • 3
  • 1
    Possible duplicate of [How do I enable C++11 in gcc?](http://stackoverflow.com/questions/16886591/how-do-i-enable-c11-in-gcc) – Francesca Nannizzi Sep 07 '16 at 15:44
  • 1
    Use `CXX` and `CXXFLAGS`. Delete your rule for `%.o: %.c`, which doesn't apply to `.cpp` files anyway, and try again. Make has predefined ("implicit", in Make terminology) rules for building `.o` targets from `.cpp` files which use the `CXX` and `CXXFLAGS` variables. – Andrew Sep 07 '16 at 15:45

1 Answers1

5

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.

πάντα ῥεῖ
  • 1
  • 13
  • 116
  • 190