cotton
October 18, 2015, 6:16pm
1
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?
Eden
October 18, 2015, 6:38pm
2
just add -std=c++11
or -std=c++11
after $(CC)
1 Like
Or add it to your CCFLAGS list
2 Likes
cotton
October 19, 2015, 2:07am
4
Thanks, I'll let you know how it goes once I try to compile my code.
1 Like
cotton
October 19, 2015, 6:28pm
5
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:
cotton@Laptop:~/Sandbox/cis250/assign/ct_cs250_hw5$ ls
ct_cs250_hw5.cpp HugeInteger.cpp HugeInteger.h makefile