Click here to Skip to main content
13,045,790 members (45,573 online)
Rate this:
Please Sign up or sign in to vote.
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.

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 3:37am

1 solution

Rate this: bad
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.
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)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.170713.1 | Last Updated 14 Apr 2012
Copyright © CodeProject, 1999-2017
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