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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T15:20:48+00:00 2026-06-15T15:20:48+00:00

I have a folder structure where all my source files are in ./src/, and

  • 0

I have a folder structure where all my source files are in ./src/, and all my object files are in ./obj/ (with the same internal directory structure, mirrored using path substitutions). I’ve created the following makefile:

$(EXECUTABLE): $(OBJECTS)
    @echo Linking $(EXECUTABLE)...
    $(CXX) $(LDLIBS) $(OBJECTS) -o $(EXECUTABLE)

%.o: $(subst o,cpp,$(subst obj/,src/,$@))
    @echo Building $@...
    $(CXX) $(CPPFLAGS) -c $(subst o,cpp,$(subst obj/,src/,$@)) -o $@

Which doesn’t work! Make keeps claiming that the object files are up to date, even when the source file is actually older than the object file. On the other hand, if I do this:

obj/main.o: src/main.cpp
    @echo Building $@...
    $(CXX) $(CPPFLAGS) -c src/main.cpp -o $@

For every source file, it works perfectly. I checked, and the two subst give the same result (obj/main.o becomes src/main.cpp as expected). Yet Make doesn’t accept the dependency for some reason.

This is giving me a lot of grief, can somebody explain where I am going wrong? I don’t understand what is going on, I thought my substitution would work the same since it gives the same output. Am I not allowed to use subst, or $@ in the dependencies or something?

  • 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-15T15:20:49+00:00Added an answer on June 15, 2026 at 3:20 pm

    You can’t use $@ in the prerequisites, only in the commands.

    But you can do this:

    $(OBJECTS): obj/%.o : src/%.cpp
        @echo Building $@ from $<...
        $(CXX) $(CPPFLAGS) -c $< -o $@
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a Java project with all source files in the src folder. This
I have a source directory structure: projectSource |---src |---include |---CMakeLists.txt and would like an
I have a files structure like this: Class (folder): - User.php - Rule.php Scripts
I'm using a library with an include structure where the .h files are all
I have an Eclipse project with the following directory structure: MyProj >> src/main/java >>
I have a folder structure with multiple SQL files each. I would like to
My physical file structure for a project I have is something like: Source folder
I have folder structure and I would like to create JSON objects based on
I have a folder structure as follows: mydomain.example ->Folder-A ->Folder-B I have a string
I have a folder structure like this: /some_folder /tmp /tmp/foo /tmp/foo/fu * /tmp/bar /tmp/bar/bah

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.