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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T15:25:46+00:00 2026-05-15T15:25:46+00:00

I have some template classes I’ve written that are dependencies for several other classes

  • 0

I have some template classes I’ve written that are dependencies for several other classes I need to compile. I have a few options as to how I can do this in my Makefile:

  1. Each class that requires a template lists its template requirements. This has the drawback of needing to recreate the dependency tree every time I want to add a new class.

  2. Make the templates into target somehow. Either by compiling them, or by making some shadow dependency tree that does not compile anything, but simply forces a recompilation in the event of one of the templates becoming modified.

Any suggestions are welcome.

  • 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-15T15:25:47+00:00Added an answer on May 15, 2026 at 3:25 pm

    As Neil Butterworth mentioned in a comment, make deals with files. Say you have a foo.cpp and a bar.h. The latter contains your template. And the former might do, for example:

    #include "bar.h"
    class Foo : public Bar<Widget> { [...] };
    

    While your Foo class inherits and thus depends on your Bar template class, you are also already declaring your file dependencies with your #includes.

    It’s those same file dependencies that you specify in your Makefile:

    foo.o: foo.cpp bar.h
            g++ -I. -o foo.o foo.cpp
    

    For this rule, make expects that the commands you specify create foo.o, based on the foo.cpp and bar.h files. If you’ve already built foo.o once, and those dependencies haven’t changed, make knows it can skip the rule altogether.

    It may seem tedious to specify file dependencies twice, but luckily dependencies in your Makefile can be automatically generated from #includes in your source code by GCC using the -M command-line parameter. You can read about this in the gcc(1) manpage. Simply take GCC’s output, save it somewhere, typically foo.d, and include that in your Makefile.

    With some wizardry, you can automate the generation of *.d dependency files in the same Makefile that builds your application.

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

Sidebar

Related Questions

I have some template code that I would prefer to have stored in a
I have some code that looks like: template<unsigned int A, unsigned int B> int
I have a web application where the masterPage/template contains some static HTML that never
Say I have a function with template type T and two other classes A
I need several C++ classes to have a static method register, however the implementation
I`m trying to display classes that have properties of type some custom class inside
I have some variables inside a template and I don't know where I assigned
I have some flatpages with empty content field and their content inside the template
I have some french letters (é, è, à...) in a django template but when
Currently, I have some code as follows template<typename Type> Type* getValue(std::string name, bool tryUseGetter

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.