Click here to Skip to main content
15,068,929 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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

1 solution

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.
   
Comments
Charmy from bangalore 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)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900