DOC PREVIEW
Rose-Hulman CSSE 432 - Compiling a single program

This preview shows page 1-2-3-4-5 out of 15 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 15 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 15 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 15 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 15 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 15 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 15 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

MakefilesMakefilesMakefilesMakefilesTutorial adapted from Tutorial adapted from http://www.eng.hawaii.edu/Tutor/Make/http://www.eng.hawaii.edu/Tutor/Make/d d and and http://www.cs.bgu.ac.il/~sadetsky/openu/http://www.cs.bgu.ac.il/~sadetsky/openu/myMakeTutorial.txtmyMakeTutorial.txtCompiling a single programprogramCompiling multiple related filesrelated filesgcc green.c blue.cORORgcc –o program1 green.c blue.cMore efficient compilationMore efficient compilationMore efficient compilationMore efficient compilationgcc –c green c => create green ogcc c green.c => create green.ogcc –c blue.c => create blue.o bl li k d t gcc green.o blue.o => link and create a.out• The “c” flag compiles and creates gpobject files while ignoring functions and variables defined externally.ySplitting your C programSplitting your C program• When you separate your C program into yp y pgmany files, keep these points in mind: – When you use a global variable, •Define it in one source fileDefine it in one source file– int global_variable;• declare it in the header file– extern int global_variable;ld h h d fl h•include the header file in the appropriate C source files– Write all function prototypes in header files and include the header files in the appropriate and include the header files in the appropriate C source files.– Exactly one of the files must have a main() functionfunction.Dependency graphs and MakefilesMakefilesTarget: Dependencies<tab> How to compileMakefileMakefileall: project1io.o: io.c io.h<tab > gcc –c io.cMakefileMakefileMakefileMakefile•Create a file called Makefile•Create a file called Makefile.• At the prompt, type “make”.Make cleanMake cleanMake cleanMake cleanclean:clean:<tab>rm –f *.oAt the prompt:make cleanTo create more than one To create more than one executableexecutableexecutableexecutable1 Include the following line in the 1. Include the following line in the Makefileall: <exe1> <exe2> all: <exe1> <exe2> ….2. Write the rest of the Makefile.3. At the prompt, type “make”.To make more than oneTo make more than oneTo make more than one….To make more than one….•If you don’t want to re-create all •If you don t want to recreate all the executables every timeaSpecify only the ones that should a.Specify only the ones that should be with “all”.ORORb. Don’t use “all”. Instead, type:make <exe1> <exe2> ….Macros in MakefilesMacros in MakefilesMacros in MakefilesMacros in MakefilesCC = gccgDEBUG = -gLFLAGS = -Wall $DEBUG -oCFLAGS W ll $DEBUGCFLAGS = -Wall –c $DEBUGmain: green.o blue.o$(CC) $LFLAGS green o blue o$(CC) $LFLAGS green.o blue.ogreen.o: green.c common.h$(CC) $CFLAGS green.c$(CC) $CFLAGS green.cblue.o: blue.c common.h$(CC) $CFLAGS blue.cReferencesReferencesReferencesReferences• http://www.mtsu.edu/~csdept/FacilitiesAndResources/make.htm#What%20make• http://www.eng.hawaii.edu/Tutor/Make/• http://www.cs.bgu.ac.il/~sadetsky/openu/myMakeTutorial.txtSingly linkedSingly linkedlistlistSingly linkedSingly


View Full Document

Rose-Hulman CSSE 432 - Compiling a single program

Download Compiling a single program
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Compiling a single program and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Compiling a single program 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?