Day 12 Makefiles Continued - PowerPoint PPT Presentation

About This Presentation
Title:

Day 12 Makefiles Continued

Description:

Once util.c is compiled, we can compile main.c using the generated object code (util.o) ... The -c option in the first line tells the compiler not to link the program. ... – PowerPoint PPT presentation

Number of Views:23
Avg rating:3.0/5.0
Slides: 7
Provided by: davidg97
Learn more at: http://www.cs.fsu.edu
Category:

less

Transcript and Presenter's Notes

Title: Day 12 Makefiles Continued


1
Day 12Makefiles Continued
  • David A. Gaitros
  • Department of Computer Science
  • Florida State University

2
Exercise on Building Makefiles
  • Assume you have a C program comprised of two
    files.
  • main.c main program.
  • util.h contains only the prototypes of the
    subroutines in util.c
  • util.c contains the subroutines used in main.c
  • util.c must be compiled before main.c because it
    must use the routines in util.c as part of its
    program.
  • Once util.c is compiled, we can compile main.c
    using the generated object code (util.o)

3
Exercise on Building Makefiles
  • Here is how you would do it manually
  • gcc -c util.h
  • gcc -o main.x main.c util.o
  • The -c option in the first line tells the
    compiler not to link the program.
  • The -o option in the second line tells the
    compiler to name the output program main.x.
    Otherwise it would name it a.out.

4
Exercise in Building a Makefile
  • Here is what the makefile would look like.
  • main.x main.c util.o
  • gcc -o main.x main.c util.o
  • util.o util.c util.h
  • gcc -c util.c
  • NOTE there are tabs before the gcc commands.

5
Examples of Makefiles
  • CC g
  • myprogram.x myprogram.o gradebook.o
  • (CC) -lcurses -o myprogram.x gradebook.o
    myprogram.o
  • myprogram.o myprogram.cpp
  • (CC) -c -I. -g -o myprogram.o myprogram.cpp
  • gradebook.o gradebook.cpp gradebook.h
  • (CC) -c -I. -g -o gradebook.o gradebook.cpp

6
Examples of Makefiles
  • CC gcc
  • DIR /home/faculty/whalley/public_html/cop5622pro
    j/lib
  • CFLAGS -g -I(DIR) -I. -c
  • LFLAGS -g
  • opt analysis.o flow.o io.o misc.o opt.o opts.o
    peephole.o regs.o vect.o
  • (CC) (LFLAGS) -o opt analysis.o flow.o io.o
    misc.o opt.o opts.o peephole.o regs.o vect.o
  • analysis.o analysis.c analysis.h (DIR)/misc.h
    (DIR)/opt.h (DIR)/vect.h
  • (CC) (CFLAGS) analysis.c
  • flow.o (DIR)/flow.c (DIR)/flow.h (DIR)/opt.h
  • (CC) (CFLAGS) (DIR)/flow.c
  • io.o (DIR)/io.c (DIR)/io.h analysis.h
    (DIR)/misc.h (DIR)/opt.h peephole.h
    (DIR)/regs.h
  • (CC) (CFLAGS) (DIR)/io.c
  • misc.o (DIR)/misc.c (DIR)/misc.h (DIR)/opt.h
  • (CC) (CFLAGS) (DIR)/misc.c
Write a Comment
User Comments (0)
About PowerShow.com