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 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 92k
  • Answers 92k
  • 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
  • Editorial Team
    Editorial Team added an answer Try this: weeksOnPlanSpan = DateTime.Now.Subtract(planStartDate.Value); May 11, 2026 at 6:22 pm
  • Editorial Team
    Editorial Team added an answer Use a typical try...catch...finally structure, and based on the specific… May 11, 2026 at 6:22 pm
  • Editorial Team
    Editorial Team added an answer You don't have to use TargetName. This works: <Page xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"… May 11, 2026 at 6:22 pm

Related Questions

I have a Java project in a SVN repository, with a bunch of .java
First a bit of background. I have been working on the MS platform for
Around here we have been working with a bunch of Visual Source Safe repositories
I am new to Windows and Visual Studio. I have a strong background in

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.