LinuxQuestions.org
Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 10-13-2012, 07:09 AM   #1
Shahid nx
Member
 
Registered: Jan 2012
Posts: 46

Rep: Reputation: Disabled
creating more than one in single makefile in c?


Hi all,
what is way to create two executable from two programs in a single make file. i.e i have programs abc.c and xyz.c and i m creating the makefile like this
xyz:xyz.o
gcc xyz.o -o xyz
abc:abc.o
gcc abc.o -o abc
abc.o:abc.c
gcc abc.c -c
xyz.o:xyz.c
gcc xyz.c -c
But when i execute make command it is only creating the xyz executable not creating abc.!! Can anyone please explain me why this is happening? and also solution for this.

Regards,
shahid nx
 
Old 10-13-2012, 09:37 AM   #2
Snark1994
Senior Member
 
Registered: Sep 2010
Location: Wales, UK
Distribution: Arch
Posts: 1,632
Blog Entries: 3

Rep: Reputation: 345Reputation: 345Reputation: 345Reputation: 345
Essentially the problem with yours is that when you type 'make' it will run the first rule, which is

Code:
gcc xyz.o -o xyz
What you need instead is

Code:
all: xyz.o abc.o
  gcc xyz.o abc.o -o executable
However, you could also do is:

Code:
OBJECTS = abc.o xyz.o

all: $(OBJECTS)
    gcc $(OBJECTS) -o executable

%.o: %.c
    gcc -c $<
So the bottom bit is a rule to change a .c file to a .o file, the middle bit says that to make the executable you need objects 'abc.o' and 'xyz.o' and how to combine them to make the executable using gcc, and the first line lists all the objects you need.

Hope this helps,

Last edited by Snark1994; 10-13-2012 at 09:39 AM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
creating a Makefile BackwardsDown Programming 1 11-26-2006 01:47 PM
Compiling multiple .c file using single command in makefile vipulc Linux - General 2 03-19-2006 12:49 AM
Creating a makefile Spike5 Solaris / OpenSolaris 1 11-24-2005 04:46 PM
creating a Makefile true_atlantis Programming 3 02-26-2004 09:35 PM
Creating a Makefile-GTK The Yeti Lives Linux - Newbie 0 06-14-2003 07:56 PM


All times are GMT -5. The time now is 09:24 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration