LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 03-04-2005, 09:20 PM   #1
pablowablo
Member
 
Registered: Apr 2004
Posts: 131

Rep: Reputation: 15
new to make... advice needed


Hello, I'm starting to learn make and I have some questions...

The following are my files and their dependencies:

main.c ---> depends on Menu.c Student.c List.c
Menu.c----> depends on Student.c List.c
Student.c--->depends on Menu.c
List.c ---> depends on nothing

my question is how do I create my makefile given the scenario?

This is what I came up with


Code:
SAS: main.o Menu.o List.o Student.o
	gcc main.o Menu.o List.o Student.o -o SAS

main.o: Menu.h Menu.c Student.h Student.c List.h List.c
	gcc  ??????????????
Menu.o: Menu.h Menu.c Student.h Student.c List.h List.c
	gcc ????????????????
Student.o: Student.h Student.c Menu.h Menu.c
	gcc ?????????????????
List.o: List.c List.h
	gcc List.c -o List.o
I'm a bit confused on the command I have to issue to compile the objects...

should it be like:
gcc Menu.c Student.c List.c -o main.o
gcc Menu.c Student.c List.c -o Menu.o
gcc Student.c Menu.c -o Student.o

???

I think it would work but I feel I'm missing something... reason is I don't think it utilizes the purpose of make in the first place..... or is this a problem with my dependencies itself?


thanks hope you can give me some advice
 
Old 03-04-2005, 10:06 PM   #2
jtshaw
Senior Member
 
Registered: Nov 2000
Location: Seattle, WA USA
Distribution: Ubuntu @ Home, RHEL @ Work
Posts: 3,892
Blog Entries: 1

Rep: Reputation: 67
I wanna ask you about your dependencies real quick... how does the circular dependency come into play? If Menu depends on Student, and Student depends on Menu... Are you declaring things in headers and included them in your program?
 
Old 03-04-2005, 10:54 PM   #3
johnMG
Member
 
Registered: Jul 2003
Location: CT, USA
Distribution: Debian Sarge (server), Etch (work/home)
Posts: 601

Rep: Reputation: 32
I'm a bit confused on the command I have to issue to compile the objects...

should it be like:
gcc Menu.c Student.c List.c -o main.o


No.

For your purposes here, it should be like
Code:
gcc -c Menu.c Student.c List.c
You don't need "-o Menu.o". The "-o" is mostly useful just for giving your executable a name. You want the "-c" so that a .o file is left behind, rather than gcc trying to link your .o file.

Next step for you is to learn how suffix rules work. :) But you don't need that for now.
 
Old 03-06-2005, 10:02 AM   #4
pablowablo
Member
 
Registered: Apr 2004
Posts: 131

Original Poster
Rep: Reputation: 15
Hello thanks for the reply... I modified my makefile like thiss:

Code:
SAS: Menu.o Student.o List.o
	gcc Menu.c Student.c List.c -o SAS

Menu.o: Menu.c Student.c List.c Menu.h Student.h List.h
	gcc -c Menu.c Student.c List.c

Student.o: Student.c List.c Student.h List.h
	gcc -c Student.c List.c

List.o: List.c List.h
	gcc -c List.c

It works, but I notice it's no different than compiling every source every time....

I think the problem is with my dependencies... When one gets edited, this has to get executed : gcc Menu.c Student.c List.c -o SAS...


or should my command be different? sorry I'm new with gcc...

Quote:
wanna ask you about your dependencies real quick... how does the circular dependency come into play? If Menu depends on Student, and Student depends on Menu... Are you declaring things in headers and included them in your program?
I do have the prototypes in header files and my code includes them...

Im, curious is there a possible scenario where circular dependencies causes errors?? Like how bout if a function uses a function that is in another source file and that function uses another function in the previous source file? Is this allowed?


Quote:

You don't need "-o Menu.o". The "-o" is mostly useful just for giving your executable a name. You want the "-c" so that a .o file is left behind, rather than gcc trying to link your .o file.

Next step for you is to learn how suffix rules work. But you don't need that for now.
Thanks! I modified my makefile... Hmm don't think I have heard of suffix rules yet
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
advice needed bshearer *BSD 2 04-18-2005 12:19 PM
Second post: Advice needed please! :-) LQtoto Linux - General 7 02-14-2004 05:22 PM
Java advice needed unholy Programming 5 10-08-2003 07:58 PM
advice needed ezra143 Linux - Laptop and Netbook 1 08-13-2003 02:44 PM
MYSQL advice needed. d3funct General 1 12-12-2001 12:48 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 07:10 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration