Solved

Make

Posted on 2004-09-28
8
256 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 23

Assisted Solution

by:brettmjohnson
brettmjohnson earned 30 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 45

Accepted Solution

by:
Kent Olsen earned 20 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Summary: This tutorial covers some basics of pointer, pointer arithmetic and function pointer. What is a pointer: A pointer is a variable which holds an address. This address might be address of another variable/address of devices/address of fu…
Windows programmers of the C/C++ variety, how many of you realise that since Window 9x Microsoft has been lying to you about what constitutes Unicode (http://en.wikipedia.org/wiki/Unicode)? They will have you believe that Unicode requires you to use…
The goal of this video is to provide viewers with basic examples to understand opening and writing to files in the C programming language.
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use nested-loops in the C programming language.

724 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