?
Solved

UNIX makefile to generate two executables

Posted on 2005-04-04
3
Medium Priority
?
720 Views
Last Modified: 2008-01-09
Hi,

For some reason my makefile only generates executables for target1 (and not target2). Even if I modify one of target2's dependants, make seems to not even aknowlege it. Also, the clean command doesn't work. Any suggestions?

/*********
makefile
**********/

taget1: main1.o functions1.o
          gcc main1.o functions1.o -o target1

taget2: main2.o functions2.o
          gcc main2.o functions2.o -o target1

main1.o: main1.c
          gcc -c main1.c

functions1.o: functions1.c
          gcc -c functions1.c

main2.o: main2.c
          gcc -c main2.c

functions2.o: functions2.c
          gcc -c functions2.c

clean:
          rm -f *.o core

thanks.
0
Comment
Question by:Kevin_P23
[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
3 Comments
 
LVL 1

Accepted Solution

by:
ppk_cbe earned 500 total points
ID: 13703400
If you are simply executing just 'make', make will execute the first rule that it sees in the makefile, which in your case is 'taget1'. To generate 'taget2', you can execute 'make taget2'.

If you want make to generate both targets when you simply execute make, you can have a rule lile

all: taget1 taget2

(I am not 100% sure that this rule works, but you get the idea, right?)
0
 

Expert Comment

by:ashish_wale
ID: 13703510
Hi,

>taget2: main2.o functions2.o
>          gcc main2.o functions2.o -o target1<--------------This part

In the second line change "target1" . It should be "target2". This should solve your problem....

As far as "Clean" is concerned I alsways invoked it as "make clean"....try doing this way....

Cheers
Ash
0
 

Author Comment

by:Kevin_P23
ID: 13703613

>> all: taget1 taget2 clean
worked to get both executables and clean.

thanks for the help!
Kevin
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

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…
This is a short and sweet, but (hopefully) to the point article. There seems to be some fundamental misunderstanding about the function prototype for the "main" function in C and C++, more specifically what type this function should return. I see so…
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.
Suggested Courses

770 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