Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: Linux Ubuntu makefile
In my application folder A, there are 3 source directories B,C and D. Folder B contains 1.cpp,2.cpp,3.cpp.
FOlder C contains 4.cpp,5.cpp,6.cpp. I have written makefile for my application which is in Application folder A. I am also having the makefiles for each subdirectories as well means makefileA in folder A and makefileB in folderB.
 
The makefile in folder A is my main application make file.
 

Now When you give make from A the corresponding folders source files get complied and the .o files for B folder are generated as 1.o,2.o,3.o in B folder itself.Similarly, for C folder the .o files 4.o,5.o,6.o are generated in C folder only.
Now My requirement is the generation of .o files should be in Folder D instead of getting generated in Folders B and C.
The Folder D should have 1.o,2.0,3.o,4.o,5.o,6.o and the .o files should not be present in Folders B and C.
 

 
Solution1:
=========
Add the following line in makefile for Folder B and also in makefile for Folder C
mv *.o A/B/C/D(path where .o should be generated/redirected)
 
Problem with Solution1:
=======================
Solution1 works but when you do changes only in one source file,for example 2.cpp, instead of compiling only 2.cpp, it compiles all the files 1.cpp,2.cpp,3.cpp,4.cpp,5.cpp,6.cpp.This is the problem what iam facing.
Could you please suggest an efficient solution.
Posted 14-Apr-12 4:37am

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Change the rules that compile object files to write them into the D directory, and the rules that read the object files to look for them there.
 
If you do a search for "OBJDIR" and "Makefile" you should be able to find plenty of examples of how to do it.
  Permalink  
Comments
Charmy from bangalore at 15-Apr-12 11:01am
   
I need the same what you have told.Can you please explain me with an example.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 George Jonsson 215
1 Kornfeld Eliyahu Peter 169
2 OriginalGriff 120
3 PIEBALDconsult 110
4 BillWoodruff 85
0 OriginalGriff 6,165
1 DamithSL 4,658
2 Maciej Los 4,087
3 Kornfeld Eliyahu Peter 3,649
4 Sergey Alexandrovich Kryukov 3,294


Advertise | Privacy | Mobile
Web03 | 2.8.141220.1 | Last Updated 14 Apr 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100