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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T20:16:31+00:00 2026-05-10T20:16:31+00:00

I have source in a bunch of subdirectories like: src/widgets/apple.cpp src/widgets/knob.cpp src/tests/blend.cpp src/ui/flash.cpp In

  • 0

I have source in a bunch of subdirectories like:

src/widgets/apple.cpp src/widgets/knob.cpp src/tests/blend.cpp src/ui/flash.cpp 

In the root of the project I want to generate a single Makefile using a rule like:

%.o: %.cpp    $(CC) -c $<  build/test.exe: build/widgets/apple.o build/widgets/knob.o build/tests/blend.o src/ui/flash.o    $(LD) build/widgets/apple.o .... build/ui/flash.o -o build/test.exe 

When I try this it does not find a rule for build/widgets/apple.o. Can I change something so that the %.o: %.cpp is used when it needs to make build/widgets/apple.o ?

  • 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. 2026-05-10T20:16:32+00:00Added an answer on May 10, 2026 at 8:16 pm

    The reason is that your rule

    %.o: %.cpp        ... 

    expects the .cpp file to reside in the same directory as the .o your building. Since test.exe in your case depends on build/widgets/apple.o (etc), make is expecting apple.cpp to be build/widgets/apple.cpp.

    You can use VPATH to resolve this:

    VPATH = src/widgets  BUILDDIR = build/widgets  $(BUILDDIR)/%.o: %.cpp       ... 

    When attempting to build ‘build/widgets/apple.o’, make will search for apple.cpp in VPATH. Note that the build rule has to use special variables in order to access the actual filename make finds:

    $(BUILDDIR)/%.o: %.cpp         $(CC) $< -o $@ 

    Where ‘$<‘ expands to the path where make located the first dependency.

    Also note that this will build all the .o files in build/widgets. If you want to build the binaries in different directories, you can do something like

    build/widgets/%.o: %.cpp         ....  build/ui/%.o: %.cpp         ....  build/tests/%.o: %.cpp         .... 

    I would recommend that you use ‘canned command sequences‘ in order to avoid repeating the actual compiler build rule:

    define cc-command $(CC) $(CFLAGS) $< -o $@ endef 

    You can then have multiple rules like this:

    build1/foo.o build1/bar.o: %.o: %.cpp     $(cc-command)  build2/frotz.o build2/fie.o: %.o: %.cpp     $(cc-command) 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 63k
  • Answers 63k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • added an answer Both FileStream and StreamReader implement IDisposable, so I would use… May 11, 2026 at 10:29 am
  • added an answer VB.Net is the natural progression of VB6, and has a… May 11, 2026 at 10:29 am
  • added an answer You can animate both the Ellipse and the line together,… May 11, 2026 at 10:29 am

Related Questions

I have source in a bunch of subdirectories like: src/widgets/apple.cpp src/widgets/knob.cpp src/tests/blend.cpp src/ui/flash.cpp In
I have an XML source in a Microsoft SSIS 2005 package and when I
I have a slow custom data source in a SSIS Dataa Flow Task.I have
For example: I'm on MS DOS, I have a source code in the folder
I have a filename in a format like: system-source-yyyymmdd.dat I'd like to be able
I currently have a source control folder in TFS with all of my source
I have a home project that really needs to be in Source Control. I
If I have a decent size asp.net page open in Source view, and hold
I have a VB6 project in Visual Source Safe 6.0. When I open the
I have a branch in an SVN tree which contains the source to a

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.