g++ features, better makefiles

Slides:



Advertisements
Similar presentations
Makefile Ansuman Banerjee Arijit Bishnu Debapriyo Majumdar Data and File Structures Lab M.Tech. Computer Science 1 st Year, Semester I Indian Statistical.
Advertisements

Compiling. Your C, C++ or Fortran program won’t work unless you compile it The compiler will build your program as an executable file (typically in the.
The make Utility Programming Tools and Environments Winter 2006.
Separate compilation Large programs are generally separated into multiple files, e.g. tuples.h, ray.h, ray.c, tuples.c main.c With several files, we can.
Makefiles  Provide a way for separate compilation.  Describe the dependencies among the project files.  The make utility.
Makefiles Tutorial adapted from and myMakeTutorial.txt.
Copyright © 2008 Pearson Addison-Wesley. All rights reserved. Chapter 12 Separate Compilation Namespaces Simple Make Files (Ignore all class references.
Systems Dev. Tutorial II: Make, utilities, & scripting Recitation Wednesday, Sept 13 th, 2006.
Basic linux shell commands and Makefiles. Log on to engsoft.rutgers.edu Open SSH Secure Shell – Quick Connect Hostname: engsoft.rutgers.edu Username/password:
The Makefile Utility ABC – Chapter 11, Motivation Small programs single file “Not so small” programs : –Many lines of code –Multiple components.
G++ and make Dan Wilson CS193 02/01/06. The g++ Compiler What happens when you call g++ to build your program? Phase 1, Compilation:.cpp files are compiled.
C/C++ Compiling.
1 SEEM3460 Tutorial Unix Introduction. 2 Introduction What is Unix? An operation system (OS), similar to Windows, MacOS X Why learn Unix? Greatest Software.
Lecture 8  make. Overview: Development process  Creation of source files (.c,.h,.cpp)  Compilation (e.g. *.c  *.o) and linking  Running and testing.
Make: the good, the bad, and the ugly Dan Berger Titus Winters
Unix Makefiles COP 3330 Lecture Notes Dr. David A. Gaitros.
Scons Writing Solid Code Overview What is scons? scons Basics Other cools scons stuff Resources.
Introduction to C Programming CE Lecture 7 Compiler options and makefiles.
Chapter Ten g++ and make1 System Programming Software Development: g++ and make.
Makefile M.A Doman. Compiling multiple objects Card.cpp -> Card.o Deck.cpp -> Deck.o main.cpp -> main.o main.o Deck.o Card.o -> Dealer.exe.
GNU Make Computer Organization II 1 © McQuain What is make ? make is a system utility for managing the build process (compilation/linking/etc).
COP 3530 Spring2012 Data Structures & Algorithms Discussion Session Week 2.
Makefiles CARYL RAHN. Separate compilation Large programs are generally separated into multiple files, e.g. main.c addmoney.c removemoney.c money.h With.
Object Oriented Programming COP3330 / CGS5409.  Assignment Submission Overview  Compiling with g++  Using Makefiles  Misc. Review.
Lecture 8  make. Using make for compilation  With medium to large software projects containing many files, it’s difficult to: Type commands to compile.
COP 3530 Spring 12 Discussion Session 1. Agenda 1.Introduction 2.Remote programming 3.Separate code 4.Compile -- g++,makefile 5.Debug -- gdb 6.Questions?
Emacs, Compilation, and Makefile C151 Multi-User Operating Systems.
Make Make is a system utility that automatically compiles your programs for you Make looks for a file named Makefile (or makefile) in the current directory.
Problem Solving With C++ Recitation – make February 2016.
Multiple File Compilation and linking By Bhumik Sapara.
Makefiles1 MAKEFILES Purpose: contain UNIX commands and will run them in a specified sequence. Syntax Definition : { Section-name: {unix command #1} …
C code organization CSE 2451 Rong Shi. Topics C code organization Linking Header files Makefiles.
Build Tools 1. Building a program for a large project is usually managed by a build tool that controls the various steps involved. These steps may include:
Makefiles & Project 1 Q&A Recitation Staff.
Object Oriented Programming COP3330 / CGS5409.  Compiling with g++  Using Makefiles  Debugging.
Brandon Packard. Why make? So far, you have probably worked on relatively small projects Coding projects can become huge My research consists of 1600.
Makefile Script file to automate program compilation and linking (making) 1. Write the "makefile" 2. Write your programs 3. Run "make" or "make -f makefile"
GNU Make Computer Organization II 1 © McQuain What is make ? make is a system utility for managing the build process (compilation/linking/etc).
UNIX Development: g++ and make CS 2204 Class meeting 8 Created by Doug Bowman, 2001 Modified by Mir Farooq Ali, 2002.
Object Oriented Programming COP3330 / CGS5409.  Assignment Submission Overview  Compiling with g++  Using Makefiles  Misc. Review.
Makefiles Manolis Koubarakis Data Structures and Programming Techniques 1.
Review Why do we use protection levels? Why do we use constructors?
Makefiles CSSE 332 Operating Systems
The make utility (original presentation courtesy of Alark Joshi)
CSE 303 Lecture 17 Makefiles reading: Programming in C Ch. 15
Brief Intro to Make CST494/ Gannod.
Hartree-Fock Program in C++.
Andy Wang Object Oriented Programming in C++ COP 3330
Compilation and Debugging
Compilation and Debugging
Makefiles Caryl Rahn.
SCMP Special Topic: Software Development Spring 2017 James Skon
What is make? make is a system utility for managing the build process (compilation/linking/etc). There are various versions of make; these notes discuss.
Prof: Dr. Shu-Ching Chen TA: Samira Pouyanfar Hector Cen Fall 2017
Makefiles and the make utility
Data Structures and Programming Techniques
Unix Programming Environment
CMPSC 60: Week 4 Discussion
CMSC 202 Additional Lecture – Makefiles
The Linux Command Line Chapter 4
SCMP Software Development Spring 2018 James Skon
Build Tools (make) CSE 333 Autumn 2018
CSCE-221 Makefile Introduction
Preparation for Assignment 2
Makefiles and the make utility
SCMP Software Development Spring 2018 James Skon
SPL – PS1 Introduction to C++.
What is make? make is a system utility for managing the build process (compilation/linking/etc). There are various versions of make; these notes discuss.
The Linux Command Line Chapter 4
The make utility (original presentation courtesy of Alark Joshi)
Presentation transcript:

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

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)

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) 

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.

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

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

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