Makefile with c++ std:11

Hi everyone,

I need to create a c++ makefile which uses the c++11 standard. I use the gcc compiler. Currently, I have a makefile which compiles code fine, except if it's using the 11 standards.

I have three files. A header file, an implementation file, and the main cpp file. The header file and implementation file share the same name (CLASS1).

Here is my current makefile.

CC = g++
#CCFLAGS = -O -Wall -Werror -ansi
FILE = ct_cs250_hw5
CLASS1 = HugeInteger

$(FILE) : $(FILE).o $(CLASS1).o
    $(CC) -o $(FILE).exe $(FILE).o $(CLASS1).o

$(FILE).o : $(FILE).cpp $(CLASS1).h
    $(CC) $(CCFLAGS) -c $(FILE).cpp

$(CLASS1).o : $(CLASS1).cpp $(CLASS1).h
    $(CC) $(CCFLAGS) -c $(CLASS1).cpp

clean:
    rm -f *.o $(FILE).exe

Do I need to add a CFLAG = -c++std:11 and add it after the the $(CC) in the $(FILE).o and $(CLASS1) lines?

just add -std=c++11 or -std=c++11 after $(CC)

1 Like

Or add it to your CCFLAGS list

2 Likes

Thanks, I'll let you know how it goes once I try to compile my code.

1 Like

It won't compile... :(

Here's the error

make: Circular HugeInteger <- HugeInteger dependency dropped.
g++ -o .cpp
g++: fatal error: no input files
compilation terminated.
make: *** [.cpp] Error 4

makefile is:

CC = g++
#CCFLAGS = -O -Wall -Werror -ansi
FILE = ct_cs250_hw5
CLASS1 = HugeInteger

$(FILE) : $(FILE).o $(CLASS1).o
    $(CC) -o $(FILE).exe $(FILE).o $(CLASS1).o

$(FILE).o : $(FILE).cpp $(CLASS1).h
    $(CC) -std=c++11 $(CCFLAGS) -c $(FILE).cpp

$(CLASS1).o : $(CLASS1).cpp $(CLASS1).h
    $(CC) -std=c++11 $(CCFLAGS) -c $(CLASS1).cpp

clean:
    rm -f *.o $(FILE).exe

Here is the ls of the directory:

[email protected]:~/Sandbox/cis250/assign/ct_cs250_hw5$ ls
ct_cs250_hw5.cpp  HugeInteger.cpp  HugeInteger.h  makefile