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 8673197
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T19:23:49+00:00 2026-06-12T19:23:49+00:00

I have couple of cpp and hpp files in directory ./src . I compile

  • 0

I have couple of cpp and hpp files in directory ./src. I compile all cpp files in one binary file, say ./bin/run. I want to re-compile only if I need i.e it or one of its header was changed.

I, probably, can create Makefile where file will be recompiled if and only if it was changed, but it’s quite uncomfortable because big part of my code is in the headers. (It’s not going to be changed, because the product is header itself and cpp files are tests).

I want to store temporary .o files in ./build

I know about g++ -MM function but I’m not sure how to use it.

I’ll glad to see solutions that use not necessary make but any other system possible if they are easy enough.

UPD
I’ll try to clarify, what’s the problem is:

New cpp’s maybe created, includes may be added or gone, etc. I don’t want to edit my makefile each time.

  • 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. Editorial Team
    Editorial Team
    2026-06-12T19:23:50+00:00Added an answer on June 12, 2026 at 7:23 pm

    You mention g++ -MM, which can do what you’re trying to do:

    include $(ALLOBJ:%.o=%.d)
    
    %.d: %.cxx
        @echo making dependencies for $<
        @g++ -MM -MP $(CXXFLAGS) $< -o $@
        @sed -i 's,$*\.o,& $@ ,g' $@
    

    Basically this defines a rule that creates .d files from .cxx files. The .d files are, in turn, required by the include statement, which requires one for each .o file in ALLOBJ.

    The last line in the dependency rule is the ‘sed magic’ that makes the dependency files regenerate themselves. If you think regular expressions are hacks at best, and evil more often than not, you can use the -MT flag.

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

Sidebar

Related Questions

Suppose one has about 50,000 different .cpp files. Each .cpp file contains just one
I have couple of input fields with the class link. All of them should
I have couple of lib files and I want to use in my project.
I have couple of dll files that need to be registered/unregistered when a Windows
I have couple .c files in my java project. How to achieve in Eclipse
I have couple of developers changes and they are all checked in to source
I have a project that contains two forms, Form1.h and Form2.h. The .cpp files
I have couple of hyperlinks on my website. What I want is to remove
I have couple of dozen pieces of data that I need to save and
I have couple of formulas and data coming from database. I want to refresh

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.