Unix/Linux Go Back    


Homework & Coursework Questions Students must use and complete the template provided. If you don't, your post may be deleted! Special homework rules apply here.

Create Makefile from source files

Homework & Coursework Questions


Closed    
 
Thread Tools Search this Thread Display Modes
    #1  
Old Unix and Linux 09-05-2015   -   Original Discussion by pintu1228
pintu1228 pintu1228 is offline
Registered User
 
Join Date: Sep 2015
Last Activity: 6 September 2015, 12:38 PM EDT
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Create Makefile from source files

1. The problem statement, all variables and given/known data:

Create a makefile for a set of source files. Several sources files are given but we are not allowed to modify them. The goal is to create a makefile such that if a change is made to any of the source code files, the project can be rebuilt by typing make at the command line.

2. Relevant commands, code, scripts, algorithms:

use vi in unix environment; -o, -I, -c

3. The attempts at a solution (include all code and scripts):


Code:
all: frprog gqprog vwprog

frprog: fr.o
        g++ -o frprog fr.o

fr.o: fr.cc pg.h
        g++ -c fr.cc

gqprog: gq.o
        g++ -o gqprog gq.o

gq.o: gq.cc ac.h bb.h
        g++ -c gq.cc -I/includes/bb.h

vwprog: vw.o
        g++ -o vwprog vw.o

vw.o: vw.cc ac.h
        g++ -c vw.cc

ac.o: ac.cc ac.h pg.h
        g++ -c ac.cc

pg.o: pg.cc pg.h
        g++ -c pg.cc


clean:
        -rm *.o


Code:
g++ -o frprog fr.o
fr.o: In function `main':
fr.cc:(.text+0x21): undefined reference to `f1()'
collect2: error: ld returned 1 exit status
Makefile:4: recipe for target 'frprog' failed
make: *** [frprog] Error 1
make: *** No rule to make target 'bb.h', needed by 'gq.o'.
g++ -o vwprog vw.o
vw.o: In function `main':
vw.cc:(.text+0x21): undefined reference to `x2()'
collect2: error: ld returned 1 exit status
Makefile:16: recipe for target 'vwprog' failed
make: *** [vwprog] Error 1
make: Target 'all' not remade because of errors.


4. Complete Name of School (University), City (State), Country, Name of Professor, and Course Number (Link to Course):

Northern Illinois University, Dekalb, IL, USA
Dr. Kirk Duffin
CSCI 689
Attached Files
File Type: rar Source files.rar (1.3 KB, 4 views)

Last edited by DukeNuke2; 09-05-2015 at 04:19 AM..
Sponsored Links
    #2  
Old Unix and Linux 09-05-2015   -   Original Discussion by pintu1228
Don Cragun's Unix or Linux Image
Don Cragun Don Cragun is offline Forum Staff  
Administrator
 
Join Date: Jul 2012
Last Activity: 19 November 2017, 7:13 AM EST
Location: San Jose, CA, USA
Posts: 10,658
Thanks: 571
Thanked 3,732 Times in 3,185 Posts
Look... We aren't going to do your homework for you. And make and gcc pretty much tell you exactly what is wrong. So tackle each reported error until you have fixed your makefile to correctly build frprog, gqprog, and vwprog.

So, let's start with your first problem:
Quote:
Code:
g++ -o frprog fr.o
fr.o: In function `main':
fr.cc:(.text+0x21): undefined reference to `f1()'
collect2: error: ld returned 1 exit status
Makefile:4: recipe for target 'frprog' failed
make: *** [frprog] Error 1

Just looking at the above output and your makefile (without even looking at your source files), tells us that fr.cc includes a function called main() and main() calls a function called f1(). And, f1() is not defined in fr.cc.

Do you have another source file that defines f1()? If so, you need to add the object file produced from that source as a dependency for frprog. If not, you need to write some code that does define it in fr.cc or add it to another file and update the dependencies in your makefile.

Moving on to your second problem... Do you have a header that isn't in the same directory as your source files (and isn't a standard header found in /usr/include), is there an option you can give to gcc to tell it to look for headers in another directory? If so, update the rules for making the object(s) that depends on that missing header to tell gcc where to find that header when building that(those) object file(s).

And, your third problem looks very similar to your first problem.

Note also that make is very picky about <tab> and <space> characters in rules in makefiles. You have shown us sequences of spaces in your sample makefile that are required to be tab characters. (We can assume that you copied the makefile out of a vi editing window instead of actually copying and pasting your makefile, but be aware that they are not interchangeable. (And, when you don't use CODE tags to show us your makefile, sequences of spaces and tabs are converted to a single space and leading spaces are discarded completely when we try to read your code. So, PLEASE use CODE tags when showing us sample input, sample output, and sample code segments. ICODE tags are fine for partial line snippets of sample code, but multi-line code segments need CODE tags; not ICODE tags.)
Sponsored Links
    #3  
Old Unix and Linux 09-05-2015   -   Original Discussion by pintu1228
pintu1228 pintu1228 is offline
Registered User
 
Join Date: Sep 2015
Last Activity: 6 September 2015, 12:38 PM EDT
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
I got most of working, just need to ask a question.

I am trying to create the gq.o file but the bb.h is located in another directory with assign1. So its like /assign1/includes/bb.h, how do I define it correctly.

it keeps giving an error saying No rule to make target 'I/assign1/includes/', needed by gq.o. Stop


Thanks
    #4  
Old Unix and Linux 09-05-2015   -   Original Discussion by pintu1228
Don Cragun's Unix or Linux Image
Don Cragun Don Cragun is offline Forum Staff  
Administrator
 
Join Date: Jul 2012
Last Activity: 19 November 2017, 7:13 AM EST
Location: San Jose, CA, USA
Posts: 10,658
Thanks: 571
Thanked 3,732 Times in 3,185 Posts
I/assign1/includes/ is a funny looking target. Show us the dependencies and rules in your makefile that mention that target.
Sponsored Links
    #5  
Old Unix and Linux 09-05-2015   -   Original Discussion by pintu1228
pintu1228 pintu1228 is offline
Registered User
 
Join Date: Sep 2015
Last Activity: 6 September 2015, 12:38 PM EDT
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts

Code:
output: fr.o vw.o ac.o pg.o gq.o
	g++ -o fr.o gq.o vw.o ac.o pg.o output

fr.o: fr.cc pg.h
	g++ -c fr.cc


vw.o: vw.cc ac.h
	g++ -c vw.cc


ac.o: ac.cc ac.h pg.h
	g++ -c ac.cc


pg.o: pg.cc pg.h
	g++ -c pg.cc


gq.o: gq.cc ac.h -I/assign1/includes bb.h	
	g++ -c gq.cc

clean:
	-rm *.o output

The gq.cc file has include "bb.h". The bb.h file is located in a sub directory under the main directory assign1.

---------- Post updated at 06:07 PM ---------- Previous update was at 06:04 PM ----------

the whole directory location is /home/turing/z1755294/assign1/assign1/includes/bb.h

the 2nd assign1 is where the other source files and header files are located.

The includes directory is what I am trying to accomplish for the gq.o
Sponsored Links
    #6  
Old Unix and Linux 09-05-2015   -   Original Discussion by pintu1228
Don Cragun's Unix or Linux Image
Don Cragun Don Cragun is offline Forum Staff  
Administrator
 
Join Date: Jul 2012
Last Activity: 19 November 2017, 7:13 AM EST
Location: San Jose, CA, USA
Posts: 10,658
Thanks: 571
Thanked 3,732 Times in 3,185 Posts
The following:

Code:
gq.o: gq.cc ac.h -I/assign1/includes bb.h	
	g++ -c gq.cc

says that the file gq.o needs to be brought up-to-date if any of the four files:

Code:
	gq.cc ac.h -I/assign1/includes bb.h

in the current working directory are newer than gq.o or if any of those files do not exist. Neither of the last two files in that list exist in the current directory, and you have not supplied any rules that tell make how to build those files. The third file in that list looks like it might be an option to gcc to tell it how to find bb.h while it is compiling gq.cc to build gq.o, but it does not tell make how to find bb.h. (But the pathname you specified for bb.h [/home/turing/z1755294/assign1/assign1/includes] does not seem to be what is specified by -I/asign1/includes.)

If you are sitting in the directory /home/turing/z1755294/assign1/assign1 when you run make and the files gq.cc and ac.h are in that directory, what pathnames (absolute or relative) can be used to enable make to find the file bb.h?
Sponsored Links
Closed

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Linux More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
automake does not create Makefile.in useless79 Shell Programming and Scripting 0 03-22-2011 03:57 PM
Makefile cant create new install path mercury Shell Programming and Scripting 2 02-10-2009 01:29 AM
Makefile compilation Error -Unable to create executable sivalives Programming 7 08-18-2007 07:06 PM
about create Makefile mzp Programming 0 11-07-2002 03:18 AM



All times are GMT -4. The time now is 10:22 AM.