Presentation is loading. Please wait.

Presentation is loading. Please wait.

g++ features, better makefiles

Similar presentations


Presentation on theme: "g++ features, better makefiles"— Presentation transcript:

1 g++ features, better makefiles
Recitation 1 cop4530 g++ features, better makefiles

2 Compiling C++ programs
Single-file programs g++ prog1.cpp Multiple-file programs To invoke the compile stage: g++ -c <file_name> Example: g++ -c frac.cpp g++ -c main.cpp To invoke the linking stage: g++ -o <target_name> <object_files> example: g++ -o frac frac.o main.o (run the program: frac)

3 Some useful flags -std=c++11 (flag for using c++11 standard features)
-std=c++11 (flag for using c++11 standard features)  -Wall (all warnings about construction and some language- specific warnings)  -pedantic (Enables warnings demanded by ISO C/C++) -I (including directories to search for header files)  -c (compile only)  -o <filename> (output rename) 

4 Makefiles Filename: makefile or Makefile
It consists of several sections: <target_name>: <dependency list> <TAB><commands> Any line that starts with a # character is a comment.

5 Make file example # This is a comment line frac: main.o frac.o g++ -o frac main.o frac.o main.o: main.cpp frac.h g++ -c main.cpp frac.o: frac.cpp frac.h g++ -c frac.cpp clean: rm *.o frac

6 Two ways to invoke commands:
make : only the first target make <target_name> Clean section: Removing the old object files To invoke: make clean

7 More advanced makefile
HOME = /home/courses/cop4530/recitation CC = g++ -Wall -pedantic PROJ = $(HOME)/rect2/makeutil  INCL = -I $(PROJ)  all: main.x  main.x: largest.o print.o main.o  $(CC) -o main.x print.o largest.o main.o  largest.o: $(PROJ)/largest.h $(PROJ)/largest.cpp  $(CC) -c $(INCL) $(PROJ)/largest.cpp  print.o: $(PROJ)/print.h $(PROJ)/print.cpp  $(CC) -c $(INCL) $(PROJ)/print.cpp  main.o: $(PROJ)/main.cpp  $(CC) -c $(INCL) $(PROJ)/main.cpp  clean:  rm -rf *.o *~ *.x 


Download ppt "g++ features, better makefiles"

Similar presentations


Ads by Google