?
Solved

Make

Posted on 2004-09-28
8
Medium Priority
?
260 Views
Last Modified: 2010-04-15
I have got 3 files.

main1.c which in there I will include node.h
node.c which in there I will include node.h
node.h

How do I create a makefile and compile them? The executable should be named "linked_list". Do you all have got any good documentation with examples on how to create a makefile?

thanks a lot.
0
Comment
Question by:ansi_c
8 Comments
 
LVL 23

Expert Comment

by:brettmjohnson
ID: 12171290
The details of the compiler etc depend on the platform and compiler environment.
But the dependencies are:

Unix makefile:

linked_list:      main1.o node.o
                  linker commands here

main1.o:            main1.c node.h
                  compile main1 command here

node.o:            node.c node.h
                  compile node command here


MS-DOS/Windows makefile:

linked_list.exe:      main1.obj node.obj
                  linker commands here

main1.obj:      main1.c node.h
                  compile main1 command here

node.obj:      node.c node.h
                  compile node command here

0
 

Author Comment

by:ansi_c
ID: 12172026
try this

main1 : main1.o node.o
cc -o main1 main1.o node.o
main1.o : main1.c node.h
cc -c main1.c
node.o : node.c node.h
cc -c node.c
clean : rm main1.o node.o


But result in an error when I typed "make"
    Makefile:2: *** missing separator.  Stop.

0
 

Author Comment

by:ansi_c
ID: 12172057
i am using Solaris
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 23

Assisted Solution

by:brettmjohnson
brettmjohnson earned 120 total points
ID: 12172618
In makefiles, whitespace matters.  I think you should learn some of the basics of make:

http://cygnus.uta.edu/cse6362/make.html

0
 

Author Comment

by:ansi_c
ID: 12173135
i knew whitespace matters but then it just does not work.
I used vim and have set tabwidth to 4 and so the TABS just does not work as normal tab.

Tried setting the option off and it works now!
Thanks a lot..

Can you refer me to more makefile documentation? Preferably with macros, variables, etc..
0
 
LVL 46

Accepted Solution

by:
Kent Olsen earned 80 total points
ID: 12174080

Hi anci_c,

There are differences in the implementation of Make().  Some are pretty subtle, some huge.  (Personally, I get a headache every time that I have to build a makefile just because I'm always stepping on these issues.)

But the basics are pretty close to universal.  You can download the Gnu Make documenation here:

http://www.gnu.org/software/make/manual/make.html


Good Luck,
Kent
0
 
LVL 3

Expert Comment

by:guynumber5764
ID: 12174922
The command must start with an actual TAB character.
0
 
LVL 4

Expert Comment

by:pankajtiwary
ID: 12176350
Hi ansi_c

You were just on the right track. Just a little modification. In make file every rule starts with a tab charecter.

Try this.

main1 : main1.o node.o
        cc -o main1 main1.o node.o
main1.o : main1.c node.h
        cc -c main1.c
node.o : node.c node.h
        cc -c node.c
clean : rm main1.o node.o

The error you are getting is because of that.

Hope this helps.
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

An Outlet in Cocoa is a persistent reference to a GUI control; it connects a property (a variable) to a control.  For example, it is common to create an Outlet for the text field GUI control and change the text that appears in this field via that Ou…
Preface I don't like visual development tools that are supposed to write a program for me. Even if it is Xcode and I can use Interface Builder. Yes, it is a perfect tool and has helped me a lot, mainly, in the beginning, when my programs were small…
The goal of this video is to provide viewers with basic examples to understand recursion in the C programming language.
The goal of this video is to provide viewers with basic examples to understand and use switch statements in the C programming language.

807 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question