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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T21:28:53+00:00 2026-05-13T21:28:53+00:00

In a makefile, I build all my .o files in a build directory: program:

  • 0

In a makefile, I build all my .o files in a build directory:

program: class1.o class2.o class3.o
    g++ $(BUILDDIR)class1.o $(BUILDDIR)class2.o $(BUILDDIR)class3.o -o $@

It would be cool to generate $(BUILDDIR)class1.o $(BUILDDIR)class2.o $(BUILDDIR)class3.o from the dependencies list…

I know that $^ would give me the list of all dependencies, separated by spaces, but I can’t deal with the sub-directory.

Is it possible ?

And if I have program: class1.o class2.o class3.o configure, can I exclude configure from the list ?

Thank you 🙂

Edit: Michael’s solutions works well, but doing that, make does not find the dependencies and has to build everything everytime… Isn’t there a simpler way, when making implicit rules like program: class1.o class2.o class3.o, to tell it to put the binaries in a build directory ?

  • 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-13T21:28:53+00:00Added an answer on May 13, 2026 at 9:28 pm

    Off the top of my head

    g++ $(addprefix $(BUILDDIR), $^) -o $@
    

    should do it.

    The Make manual has a list of these functions in section 8.3.

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

Sidebar

Related Questions

My goal is to have all object files built in a .objs directory instead
I have several hundred files in a non-flat directory structure. My Makefile lists each
My build process consists of Qt's qmake Makefile generator and the typical make utility
I have a Makefile building many C files with long long command lines and
I am trying to build a arm toolchain from scratch. I am referring to
I have a working makefile that builds with mingw32. Now i renamed that makefile
Our build is dog slow. It uses nested gnu makefiles on linux. It creates
I have a makefile template to compile a single DLL (for a plugin system).
I have a Makefile where most of my targets are created generically through a
In a makefile, I have the following line: helper.cpp: dtds.h Which ensures that helper.cpp

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.