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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T10:45:49+00:00 2026-06-13T10:45:49+00:00

I have some limited knowledge of GNU makefile that has failed me at the

  • 0

I have some limited knowledge of GNU makefile that has failed me at the moment.

I have a class declaration file: mdfTree.h, an implementation of the class mdfTree.cpp, and a mdfTree_x.cpp file with a main where I create an object of class mdfTree and call its public functions, which in turn call some private member variables of mdfTree.

I am compiling it with the Makefile:

CXX=g++
CXXFLAGS=-g -Wall -W -Wconversion -Wshadow -Wcast-qual -Wwrite-strings $(shell root-config --cflags --gl\
ibs)
LDFLAGS=-g $(shell root-config --ldflags)
LDLIBS=$(shell root-config --libs)

mdfTree_x: mdfTree_x.o
        g++ $(LDFLAGS) -o mdfTree_x mdfTree_x.o $(LDLIBS)

mdfTree_x.o: mdfTree_x.cpp
        g++ $(LDFLAGS) $(CXXFLAGS) -c mdfTree_x.cpp

mdfTree.cpp and mdfTree_x.cpp has an #include mdfTree.h in it. Does mdfTree_x.cpp need #include mdfTree.cpp as well?

I think my Makefile is wrong because a public function from class mdfTree can’t see a private variable of the same class, when I try to compile. Also, when I insert a syntax error into mdfTree.h, then the compiler doesn’t pick it up. How do I tell Makefile that mdfTree_x needs to use/compile mdfTree.h/.cpp?

  • 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-13T10:45:50+00:00Added an answer on June 13, 2026 at 10:45 am

    You’ll need to explicitly add all of the dependancies, in this case your executable depends on mdfTree.o having been built and mdfTree.o and mdfTree_x.o depend on mdfTree.h. Your dependancies should be like

    mdfTree_x:mdfTree_x.o mdfTree.o
    mdfTree.o:mdfTree.cpp mdfTree.h
    mdfTree_x.o:mdfTree_x.cpp mdfTree.h
    

    Some compilers (e.g. gnu & intel) are able to automatically list header dependancies in make format. For example this makefile will regenerate the executable when any of mdfTree_x.cpp, mdfTree.cpp or mdfTree.h is changed:

    # Compiler flags...
    CPPFLAGS+=-MMD -MP
    mdfTree_x:mdfTree_x.o mdfTree.o
    -include mdfTree_x.d mdfTree.d
    

    The CPPFLAGS will create a .d file with header dependancies when compiling, the -include line will try to include these into the makefile if present (if they’re not present the source file is going to be recompiled anyway, so extra dependancies don’t matter). The contents of the .d file will be something like

    mdfTree.o:mdfTree.h
    

    Also, you don’t need to explicitly write make rules in most cases – for instance if you have a file foo.o listed as a dependancy gnu make’s default rules are to run

    $(CXX) $(CPPFLAGS) $(CXXFLAGS) -c -o foo.o foo.cpp
    

    (and similar for other languages). Similarly linking is automatic if the executable name matches one of the object files, e.g.

    foo:foo.o
    

    will run (note CC not CXX)

    $(CC) $(LDFLAGS) -o foo foo.o $(LDLIBS)
    

    Using the default rules keeps makefiles simpler, and also lets you use environment variables to set up a default compiler.

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

Sidebar

Related Questions

I need some help with PHP Class. I have limited knowledge about how it
In my limited experience, I've been on several projects that have had some sort
I am new bee in Android, so for that I have only limited knowledge
I have some arbitrary pixel data that I want to save as a PNG.
I have some text lines like that : vt_wildshade2^508^508 vt_ailleurs2^1188^1188 ... vt_high2^13652^13652 Is it
I have some code that will change the background color of a specific label
i have some problems with a Query seem IN dosen't work with Group_concat, that
Since I still have a limited knowledge of LINQ, I figured I would ask
I'm new to design patterns, and thus have a limited knowledge of what all
I've found some limited use in chaining class functions, say $class->setUser('foo')->getInfo() (bad example) although

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.