#[1]Stack Overflow [2]RSS [3]logo homepage [4]login | [5]about | [6]faq ____________________________ * [7]Questions * [8]Tags * [9]Users * [10]Badges * [11]Unanswered * [12]Ask Question [13]gcc dependency generation for a different output directory vote up 1 vote down star I'm using gcc to generate a dependency file but my build rules put the output into a subdirectory. Is there a way to tell gcc to put my subdirectory prefix in the dependency file it generates for me? gcc $(INCLUDES) -E -MM $(CFLAGS) $(SRC) >>$(DEP) [14]c++ [15]gcc [16]makefile [17]dependency offensive? asked Sep 18 at 21:46 [18][2db54153755add15ae67c16bfba9b7e5?s=32&d=identicon&r=PG] [19]KPexEA 2,312●2●19 add comment JavaScript is needed to access comments. 4 Answers: [20]Oldest[21]Newest[22]Votes vote up 1 vote down check The answer is in the [23]GCC manual: use the -MT flag. -MT target Change the target of the rule emitted by dependency generation. By default CPP takes the name of the main input file, deletes any directory components and any file suffix such as `.c', and appends the platform's usual object suffix. The result is the target. An -MT option will set the target to be exactly the string you specify. If you want multiple targets, you can specify them as a single argument to -MT, or use multiple -MT options. For example, -MT '$(objpfx)foo.o' might give $(objpfx)foo.o: foo.c [24]link|offensive? answered Sep 19 at 3:27 [25][139450632a8b42b6f4564d6448e33688?s=32&d=identicon&r=PG] [26]bk1e 2,104●1●10 add comment JavaScript is needed to access comments. vote up 0 vote down If there is an argument to gcc to do this, I don't know what it is. We end up piping the dependency output through sed to rewrite all occurrences of .o as ${OBJDIR}/.o [27]link|offensive? answered Sep 18 at 21:52 [28][a5274c69de87610590b2f62c2fa3ad0d?s=32&d=identicon&r=PG] [29]Denton Gentry 4,976●5●17 add comment JavaScript is needed to access comments. vote up 0 vote down Ok, just to make sure I've got the question right: I'm assuming you have test.c which includes test.h, and you want to generate subdir/test.d (while not generating subdir/test.o) where subdir/test.d contains subdir/test.o: test.c test.h rather than test.o: test.c test.h which is what you get right now. Is that right? I was not able to come up with an easy way to do exactly what you're asking for. However, looking at [30]http://www.gnu.org/software/gcc/news/dependencies.html, if you want to create the .d file while you generate the .o file, you can use gcc $(INCLUDES) -MMD $(CFLAGS) $(SRC) -o $(SUBDIR)/$(OBJ) (Given SRC=test.c, SUBDIR=subdir, and OBJ=test.o) This will create both subdir/test.o and subdir/test.d, where subdir/test.d contains the desired output as above. Hope that helps. [31]link|offensive? answered Sep 18 at 22:38 [c749fe5f20f7e2045cf312767496d0b4?s=32&d=identicon&r=PG] Emile add comment JavaScript is needed to access comments. vote up 0 vote down 1. [GNU] make gets angry if you don't place the output in the current directory. What you really should do is run make from the build directory, and use the VPATH make variable to locate the source code. If you lie to a compiler, sooner or later it will take its revenge. 2. If you insist on generating your objects and dependencies in some other directory, you need to use the -o argument as answered by Emile. [32]link|offensive? answered Sep 18 at 23:10 [33][aea3ad606f964cb4b710951d75318d6a?s=32&d=identicon&r=PG] [34]florin 1,212●1●13 add comment JavaScript is needed to access comments. Your Answer: ______________________________________________________________________ ______________________________________________________________________ ______________________________________________________________________ ______________________________________________________________________ ______________________________________________________________________ ______________________________________________________________________ ______________________________________________________________________ ______________________________________________________________________ ______________________________________________________________________ ______________________________________________________________________ ______________________________________________________________________ ______________________________________________________________________ ______________________________________________________________________ ______________________________________________________________________ ______________________________________________________________________ community wiki [_] ____________________ OpenID Login: ________________________________________ Get an [35]OpenID or Name: ______________________________ Email: (never shown) ________________________________________ Home Page: ________________________________________ Post Your Answer Not the answer you're looking for? Browse other questions tagged [36]c++ [37]gcc [38]makefile [39]dependency or [40]ask your own question. Hello World! Stack Overflow is a collaboratively edited question and answer site for programmers — regardless of platform or language. It's 100% free, no registration required. [41]about » [42]faq » tagged [43]c++ × 4809 [44]gcc × 223 [45]makefile × 76 [46]dependency × 27 asked 5 months ago viewed 356 times latest activity 5 months ago [47]MIX 09: The Next Web Now, March 18-20, The Venetian Las Vegas Related [48]Different dependency settings for ‘Debug’ and ‘Release’ build configuration in VisualC++ 6.0 [49]How to exclude all transitive dependencies of a Maven dependency [50]GCC compiling a dll with __stdcall [51]Need a makefile dependency rule that can handle missing files [52]Error: The Side-by-Side configuration information in “BLAH.EXE” contains errors. [53]Is there a tool to automatically fetch build dependencies under Debian or Ubuntu? [54]Is it possible to simulate installation of Debian packages, still marking them installed? [55]circular dependencies between dlls with visual studio [56]Using mock objects outside of testing, bad practice? [57]Maven : OSGI, bundles and multi-modules projects [58]Sharepoint Web Part Management [59]Good tool to generate dependency diagram? [60]How should I detect unnecessary #include files in a large C++ project? [61]How can you re-arrange items in an array based on its dependencies? and also detect any cyclic dependency [62]Resolve dependencies on data model without cascading delete [63]ASP.NET web hosting - Special Offer! [64]feed icon [65]question feed [66]about this site | [67]faq | [68]blog | [69]podcast | [70]privacy policy | [71]contact us | [72]feedback always welcome [73]cc-wiki, PEAK Internet svn revision: 2544 Stack Overflow works best with JavaScript enabled References 1. file://localhost/opensearch.xml 2. file://localhost/feeds/question/97338 3. file://localhost/ 4. file://localhost/users/login?returnurl=%2fquestions%2f97338%2fgcc-dependency-generation-for-a-different-output-directory%2f99282 5. file://localhost/about 6. file://localhost/faq 7. file://localhost/questions 8. file://localhost/tags 9. file://localhost/users 10. file://localhost/badges 11. file://localhost/unanswered 12. file://localhost/questions/ask 13. file://localhost/questions/97338/gcc-dependency-generation-for-a-different-output-directory 14. file://localhost/questions/tagged/c%2b%2b 15. file://localhost/questions/tagged/gcc 16. file://localhost/questions/tagged/makefile 17. file://localhost/questions/tagged/dependency 18. file://localhost/users/13676/kpexea 19. file://localhost/users/13676/kpexea 20. file://localhost/questions/97338?sort=oldest#sort-top 21. file://localhost/questions/97338?sort=newest#sort-top 22. file://localhost/questions/97338?sort=votes#sort-top 23. http://gcc.gnu.org/onlinedocs/gcc-4.3.2/cpp/Invocation.html 24. file://localhost/questions/97338/gcc-dependency-generation-for-a-different-output-directory/99282#99282 25. file://localhost/users/8090/bk1e 26. file://localhost/users/8090/bk1e 27. file://localhost/questions/97338/gcc-dependency-generation-for-a-different-output-directory/97374#97374 28. file://localhost/users/4761/denton-gentry 29. file://localhost/users/4761/denton-gentry 30. http://www.gnu.org/software/gcc/news/dependencies.html 31. file://localhost/questions/97338/gcc-dependency-generation-for-a-different-output-directory/97710#97710 32. file://localhost/questions/97338/gcc-dependency-generation-for-a-different-output-directory/97893#97893 33. file://localhost/users/18308/florin 34. file://localhost/users/18308/florin 35. http://openid.net/get/ 36. file://localhost/questions/tagged/c%2b%2b 37. file://localhost/questions/tagged/gcc 38. file://localhost/questions/tagged/makefile 39. file://localhost/questions/tagged/dependency 40. file://localhost/questions/ask 41. file://localhost/about 42. file://localhost/faq 43. file://localhost/questions/tagged/c%2b%2b 44. file://localhost/questions/tagged/gcc 45. file://localhost/questions/tagged/makefile 46. file://localhost/questions/tagged/dependency 47. http://2009.visitmix.com/MIXtify/TenKGallery.aspx?stackoverflow 48. file://localhost/questions/142996/different-dependency-settings-for-debug-and-release-build-configuration-in-vi 49. file://localhost/questions/547805/how-to-exclude-all-transitive-dependencies-of-a-maven-dependency 50. file://localhost/questions/107549/gcc-compiling-a-dll-with-stdcall 51. file://localhost/questions/239004/need-a-makefile-dependency-rule-that-can-handle-missing-files 52. file://localhost/questions/254076/error-the-side-by-side-configuration-information-in-blah-exe-contains-errors 53. file://localhost/questions/210122/is-there-a-tool-to-automatically-fetch-build-dependencies-under-debian-or-ubuntu 54. file://localhost/questions/140340/is-it-possible-to-simulate-installation-of-debian-packages-still-marking-them-in 55. file://localhost/questions/362830/circular-dependencies-between-dlls-with-visual-studio 56. file://localhost/questions/367308/using-mock-objects-outside-of-testing-bad-practice 57. file://localhost/questions/375172/maven-osgi-bundles-and-multi-modules-projects 58. file://localhost/questions/377457/sharepoint-web-part-management 59. file://localhost/questions/100372/good-tool-to-generate-dependency-diagram 60. file://localhost/questions/74326/how-should-i-detect-unnecessary-include-files-in-a-large-c-project 61. file://localhost/questions/546586/how-can-you-re-arrange-items-in-an-array-based-on-its-dependencies-and-also-dete 62. file://localhost/questions/536425/resolve-dependencies-on-data-model-without-cascading-delete 63. http://www.discountasp.net/go/go.aspx?i=5955 64. file://localhost/feeds/question/97338 65. file://localhost/feeds/question/97338 66. file://localhost/about 67. file://localhost/faq 68. http://blog.stackoverflow.com/ 69. http://itc.conversationsnetwork.org/series/stackoverflow.html 70. file://localhost/privacy 71. mailto:team@stackoverflow.com 72. http://stackoverflow.uservoice.com/ 73. LYNXIMGMAP:file://localhost/home/abaumann/projects/WolfBones/docs/makefiles/99282.html#footermap