Create Makefile from source files

 
Thread Tools Search this Thread
Homework and Emergencies Homework & Coursework Questions Create Makefile from source files
# 1  
Old 09-05-2015
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

Last edited by DukeNuke2; 09-05-2015 at 04:19 AM..
# 2  
Old 09-05-2015
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.)
# 3  
Old 09-05-2015
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 09-05-2015
I/assign1/includes/ is a funny looking target. Show us the dependencies and rules in your makefile that mention that target.
# 5  
Old 09-05-2015
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
# 6  
Old 09-05-2015
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?
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Programming

Makefile instructions to create directories (CentOS7 , GNU Make 3.82)

Hello, My makefiles are set up to generate an environment specific build directory based on the local configuration and some values passed to make. It generally looks like, # compilers, may be passed to make CC++ = g++ FCOMP = gfortran # version of program, may be passed to make ver =... (4 Replies)
Discussion started by: LMHmedchem
4 Replies

2. UNIX for Dummies Questions & Answers

Create a tgz from source FreeBSD

Hello, i'm having a problem here with FreeBSD 9.2 . I've created a directory and downloaded the latest ntp-4.2.8p1-beta2 from ntp.org. Untar then into the directory and then ./configure all went OK. Then i had to modify some parameters in the config.h created with ./configure . Then make... (2 Replies)
Discussion started by: Board27
2 Replies

3. Linux

Create a bootable PXE image from build kernel source code

Hi, Can i just ask how I can create a bootable PXE image from the built kernel source. What files do I need to get? Thanks! (1 Reply)
Discussion started by: h0ujun
1 Replies

4. Shell Programming and Scripting

automake does not create Makefile.in

hi all, I have written a simple C program hello.c and a Makefile.ac but when i try to run automake it does not create Makefile.in hence I am not able to run ./configure command in my directory. Following are the containts of my prog. hello.c -------- Code: #include<stdio.h> main() {... (0 Replies)
Discussion started by: useless79
0 Replies

5. Homework & Coursework Questions

Help with Simple Multi-Level Makefile (Extremely New at Makefile)

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted! 1. The problem statement, all variables and given/known data: Basically, the prompt is make a makefile with various sub makefiles in their respective subdirectories. All code... (1 Reply)
Discussion started by: Tatl
1 Replies

6. Shell Programming and Scripting

ksh script to create a generic csv file from different source formats

Hi all, I have a requirement to create a "superset" file out of a number of different sources with some different and some same columns. We intend to have a manually updateable SuperSetCols.csv which would look like "ColA","ColB","ColC","ColD","ColE","ColF","ColG" so someday we may add... (3 Replies)
Discussion started by: Leedor
3 Replies

7. Shell Programming and Scripting

Makefile cant create new install path

..... (2 Replies)
Discussion started by: mercury
2 Replies

8. UNIX for Dummies Questions & Answers

create raidctl mirror with mounted source parition

I am mirroring a single partition drive with raidctl. The source partition was mounted when I created the mirror with raidctl -c c1t1d0 c1t3d0. The source disk was defined with s2 and s6 only. I didn't think to umount it first. Is there a problem with that? (2 Replies)
Discussion started by: csgonan
2 Replies

9. Programming

Makefile compilation Error -Unable to create executable

Hi , While trying to compile a PRO*C code on unix using makefile i get the following errors. i am now working on a 10g migration (from 8i) ... these makefile perfectly work in previous version. ld: fatal: file... (7 Replies)
Discussion started by: sivalives
7 Replies

10. Programming

about create Makefile

hello! i want to create a Makefile on the freebsd 4.5,so i vi the hello.c #include int main(int argc, char** argv) { printf(''Hello, GNU!\n''); return 0; } #autoscan #cp configure.scan configure.in #vi configure.in modify:AC_OUTPUT AC_OUTPUT(Makefile) #aclocal #autoconf... (0 Replies)
Discussion started by: mzp
0 Replies
Login or Register to Ask a Question