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

  • Home
  • SEARCH
  • 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 6989257
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T19:11:18+00:00 2026-05-27T19:11:18+00:00

I’m relatively new to (GNU) Make, and find it incedibly difficult. I consider switching

  • 0

I’m relatively new to (GNU) Make, and find it incedibly difficult. I consider switching to SCons, but still, I’d like to understand.

I have a makefile in a folder, that contains subdirectories ./src, ./obj/[release|debug] and ./bin[release|debug]. The makefile should be able to grab the C++ sources in ./src, compile them into object files in the appropriate ./obj directory, and link these object files and put the result in the appropriate ./bin directory. Here is my makefile (edited for simplicity):

CONFIG = release
#CONFIG = debug

OBJS = Container.o

OBJDIR = obj/$(CONFIG)
BINDIR = bin/$(CONFIG)

VPATH = src $(BINDIR)
vpath %.o $(OBJDIR)

.PHONY: release

release:  $(OBJS)
    $(CXX) $(LXXFLAGS) -o $(BINDIR)/$@ $^

Container.o: Container.cpp Container.hpp
    $(CXX) -c $(CXXFLAGS) -o $(OBJDIR)/$@ $<

The first time I run make, the “release” target will search for “Container.o” in the current folder, as well as in $(OBJDIR). Failing to find it, the secong target will be correctly executed, generating the object file in the correct folder. The “release” target will then execute, but the linker will complain that “Container.o” is not found…

The second time I run make, the “release” target will search for “Container.o” and find it in $(OBJDIR). The linker will then execute correctly (the path where “Container.o” has been found is prepended to the filename).

Is there a way to make it work in a single pass? It drives me crazy!

  • 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-27T19:11:19+00:00Added an answer on May 27, 2026 at 7:11 pm

    Make does have a long learning curve, and you’re attempting something tricky (and which runs right into one of Make’s big weaknesses, poor wildcard handling). I’m not sure that my answer will help more than confuse, but at least it will solve your specific problem.

    If you want to use the CONFIG approach, this will do it:

    CONFIG = release
    #CONFIG = debug                                                                 
    
    OBJS = Container.o
    
    TRUE_OBJS = $(addprefix obj/$(CONFIG)/, $(OBJS))
    
    vpath %.cpp src
    
    .PHONY: $(CONFIG)
    
    $(CONFIG): bin/$(CONFIG)/$(CONFIG)
    
    bin/$(CONFIG)/$(CONFIG): $(TRUE_OBJS)
        $(CXX) $(LXXFLAGS) -o $@ $^                                               
    
    $(TRUE_OBJS): obj/$(CONFIG)/%.o : %.cpp
        $(CXX) -c $(CXXFLAGS) -o $@ $<
    

    But you can do without it (and without the chore of editing the makefile whenever you want to change configurations):

    OBJS = Container.o
    
    vpath %.cpp src
    
    .PHONY: release debug
    
    release: bin/release/release
    debug: bin/debug/debug
    
    bin/release/release: $(addprefix obj/release/, $(OBJS))
    bin/debug/debug: $(addprefix obj/debug/, $(OBJS))
    
    bin/release/release bin/debug/debug:
        $(CXX) $(LXXFLAGS) -o $@ $^   
    
    obj/release/%.o obj/debug/%.o: %.cpp
        $(CXX) -c $(CXXFLAGS) -o $@ $<                                            
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Seemingly simple, but I cannot find anything relevant on the web. What is the
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
I would like to count the length of a string with PHP. The string
For some reason, after submitting a string like this Jack’s Spindle from a text
I am trying to understand how to use SyndicationItem to display feed which is
I've got a string that has curly quotes in it. I'd like to replace
I have a French site that I want to parse, but am running into
I want use html5's new tag to play a wav file (currently only supported

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.