LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices



Reply
 
Search this Thread
Old 08-31-2006, 05:36 AM   #1
George2
Member
 
Registered: Oct 2003
Posts: 354

Rep: Reputation: 30
directory access problem when compile .c into .o using GNU make


Hello everyone,


I am meeting with a problem when using GNU make to compile two .c files into related .o files.

My situation is, foo.c is under foo sub-directory and goo.c is inder goo sub-directory. I want to put both output foo.o and goo.o into debug sub-directory.

Currently, I have written the following statements in Makefile,

SRC = foo/foo.c goo/goo.c
OBJ = debug/foo.o debug/goo.o

But I am confused about how to write a rule to compile them, since the source files are in different directories and the output directory for .o files are in another directory (debug).

I think I can write two rules, one for foo/foo.c --> debug/foo.o and the other for goo/goo.c --> debug/goo.o, but I think it is not a good way if I have a lot of source files and seems stupid.

Could anyone help please?


thanks in advance,
George
 
Old 08-31-2006, 06:42 AM   #2
KenJackson
Member
 
Registered: Jul 2006
Location: Maryland, USA
Distribution: Fedora, Arch
Posts: 572

Rep: Reputation: 64
Try an implicit rule:
Code:
%.o : %.c
(TAB)$(CC) -c $(CCFLAGS) -o debug/$(F@) $<
%.o and %.c match an object file and the corresponing source file.
$(F@) is the filename portion of the target.
$< is the first prerequisite.

BTW, here is the GNU make manual.
 
Old 08-31-2006, 11:26 AM   #3
George2
Member
 
Registered: Oct 2003
Posts: 354

Original Poster
Rep: Reputation: 30
Cool, KenJackson!


Quote:
Originally Posted by KenJackson
Try an implicit rule:
Code:
%.o : %.c
(TAB)$(CC) -c $(CCFLAGS) -o debug/$(F@) $<
%.o and %.c match an object file and the corresponing source file.
$(F@) is the filename portion of the target.
$< is the first prerequisite.

BTW, here is the GNU make manual.
Let me try it!


regards,
George
 
  


Reply

Tags
make


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
cannot compile my program anymore (autotools, gnu make) sterrenkijker Programming 5 07-27-2006 05:52 AM
Problem running ifdef in GNU make 3.80 jennifer29 Linux - Newbie 1 03-03-2006 05:56 AM
NFS directory access problem waelaltaqi Linux - Networking 2 11-05-2005 11:25 PM
faad compile problem make not working dtra Linux - Software 4 10-05-2005 05:41 AM
kernel compile for newbie directory problem mipia Slackware 13 07-04-2003 03:30 AM


All times are GMT -5. The time now is 06:41 PM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration