Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 145715
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T08:28:22+00:00 2026-05-11T08:28:22+00:00

We’re having some discussion lately about the way we handle .d files for dependencies

  • 0

We’re having some discussion lately about the way we handle .d files for dependencies in our make-based build process. The issue has been raised that sometimes the .d files can become corrupted when builds are interrupted.

We’re using the .DELETE_ON_ERROR target to ensure that if a build is interrupted or fails, the object files that it was in the process of generating are deleted. However we’re also using GCC to generate .d files at compile time which would need to be deleted as well. There doesn’t appear to be a straightforward way to tell make about this.

So the question is, is there a way we can coax make to delete both our object and our dependency files in the case of an error? Is there some way we can set up the rules so that it knows that both the .d and .o files are generated at the same time and need to be deleted if there’s an error?

Alternately, is there something else we can do to fix the problem of corrupt .d files? One suggestion along these lines is to generate the .d files with a temporary name and have a separate post-compile step per file that copies it to the correct name.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-11T08:28:23+00:00Added an answer on May 11, 2026 at 8:28 am

    Generally speaking, GNU make doesn’t support targets with multiple outputs. However, there is an exception to that rule: pattern rules. If you can structure your makefile such that it uses pattern rules to generate the object files, you may be able to achieve your goals. For example:

    .DELETE_ON_ERROR:  all: foo.o  %.o %.d: %.c     @touch $*.d     @touch $*.o     @exit 1 

    You’ll see that with this makefile when the ‘error’ is detected in the rule, both the .d and the .o file are deleted. The advantage to this approach is that it more accurately expresses the dependency graph by describing how the .d file is to be generated and what rule will produce it.

    Alternatively, a common paradigm in this case is just as you suggested: have GCC generate the .d file into a temporary file name and only move it into place after the GCC command has completed successfully. Usually this is accomplished with a trick of the shell:

    all: foo.o  %.o: %.c     gcc -o $@ -MMD -MF $(basename $@).d.tmp -c $< \         && mv $(basename $@).d.tmp $(basename $@).d 

    Here the ‘magic’ trick is the use of the GCC flags -MMD, which generates the dependency file as a side-effect of compilation, and -MF, which lets you specify the output name for the dependency file; and the use of the shell cmd1 && cmd2 syntax, which causes the shell to only execute cmd2 if cmd1 exits successfully.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We're building an app, our first using Rails 3, and we're having to build
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have thousands of HTML files to process using Groovy/Java and I need to
I have just tried to save a simple *.rtf file with some websites and
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am reading a book about Javascript and jQuery and using one of the
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
Configuring TinyMCE to allow for tags, based on a customer requirement. My config is
We are using XSLT to translate a RIXML file to XML. Our RIXML contains

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.