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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T17:15:51+00:00 2026-05-15T17:15:51+00:00

I have a project with 50+ .h files and 50+ .cpp files. I’m using

  • 0

I have a project with 50+ .h files and 50+ .cpp files. I’m using make to build a project, which looks something like this (it’s just a piece of an entire file):

HEADERS := $(shell find $(INCLUDE) -name "*.h")
%.obj: %.cpp $(HEADERS)
    $(CPP) $(CPPFLAGS) -fPIC -o $@ -g -c $<

When I’m making changes to one .h file, the whole project has to be re-compiled. It’s annoying and time-consuming. But I don’t want to hard-code file dependencies inside Makefile, since it’s even more time-consuming. I would like to have some make-like tool, which will find dependencies right inside my .cpp/.h files, automatically. Any suggestions? Thanks in advance!

  • 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-05-15T17:15:52+00:00Added an answer on May 15, 2026 at 5:15 pm

    Simplest way:

    depend:
        g++ -M *.cpp >.depends
    
    -include .depends
    

    Better way:

    SRC=foo.cpp bar.cpp ...
    OBJ=$(patsubst %.cpp,%.o,$(SRC))
    DEPS=$(patsubst %.o,.deps/%.o.dep,$(OBJ))
    
    all: .deps
    
    .deps: 
         mkdir -p .deps
    
    .cpp.o:
        $(CXX) $(CXXFLAGS) -MD -MF .deps/$@.dep -c -o $@ $<
    
    -include $(DEPS)
    

    So compiler will generate all dependencies for each file during build automatically.

    Or even better: use Autotools, CMake or other build system that does this job for you.

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

Sidebar

Related Questions

I have a (partial) qmake project file like this: TEMPLATE=lib TARGET=whatever SOURCES=whatever.cpp HEADERS=whatever.h This
My project directory looks like this: /project Makefile main /src main.cpp foo.cpp foo.h bar.cpp
I'm practicing using mulitple files and header files etc. So I have this project
Suppose I have a VC++ project containing number of Source (.cpp) files (e.g. 5),
I have project asp.net with namespace test and I'm using resources (files Resource.resx and
I have a project using ASIHTTP to multi download files from a site when
I have a c++ project with various extensions for the source files (.cpp, .c,
I have an online repository with some .h and .cpp files that make up
I have a CUDA project. It consists of several .cpp files that contain my
I´ve got one project, where all my .h and .cpp files are included. This

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.