[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 721
  • Last Modified:

UNIX makefile to generate two executables

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
Kevin_P23
Asked:
Kevin_P23
1 Solution
 
ppk_cbeCommented:
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
 
ashish_waleCommented:
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
 
Kevin_P23Author Commented:

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

thanks for the help!
Kevin
0

Featured Post

Identify and Prevent Potential Cyber-threats

Become the white hat who helps safeguard our interconnected world. Transform your career future by earning your MS in Cybersecurity. WGU’s MSCSIA degree program was designed in collaboration with national intelligence organizations and IT industry leaders.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now