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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T00:49:35+00:00 2026-06-12T00:49:35+00:00

I have the following idea: All the source files are in a SRC directory

  • 0

I have the following idea:
All the source files are in a SRC directory while all the object files are kept in a OBJ directory. In the GNU makefile I want to automatically search for all source files and create a list of source file objects and a list of o-file objects. I tried the following two syntaxes, which me all get a

No rule to make target `/home/Serial/obj/Serial.o’, needed by …

here are the ideas:

c_files = $(wildcard $(SRC)/*.cpp)
o_files = $(patsub %.c,%.o,$(c_files) )


c_files = $(wildcard $(SRC)/*.cpp)
o_files = $(patsub $(SRC)/%.c,$(OBJ)/%.o,$(c_files) )

The c_files variable seems to be correctly filled, but I cannot get the object list created. The second idea should work, according to documentation, but does not. What is wrong with the replace statement.

To be clear: I expect to have e.g.

c_files = src/file1.cc src/file2.cc src/file109.cc

from which I want to create the following list

o_files = obj/file1.o obj/files.o obj/file109.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. Editorial Team
    Editorial Team
    2026-06-12T00:49:36+00:00Added an answer on June 12, 2026 at 12:49 am

    There’s an easier way:

    o_files = $(c_files:.cpp=.o)
    

    And to get a pattern that automatically compiles object files:

    obj/%.o: src/%.cpp
        $(CXX) $(CXXFLAGS) $(CPPFLAGS) -c $^ -o $@
    

    Combining:

    c_files = $(wildcard $(SRC)/*.cpp)
    o_files = $(c_files:.cpp=.o)
    
    all: $(PROG)
    
    $(OBJ)/%.o: $(SRC)/%.cpp
        $(CXX) $(CXXFLAGS) $(CPPFLAGS) -c $^ -o $@
    
    $(PROG): $(o_files)
        $(LD) $(LDFLAGS) $^ -o $@
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is this possible at all? The idea is to have the following: if ($some_statement)
I have the following makefile: OUTPUTDIR = build all: v12target v13target v12target: INTDIR =
I had the following idea: Say we have a webapp written using django which
I have following problem, Code: String a=Yeahh, I have no a idea what's happening
has anyone an idea why I have the following problem with passing locals to
The idea is that say you have the following table. ------------- | oID |
Having a deadlock in webservice + hibernate... No idea why. I have the following
I have no idea why this wont work but I have tried the following:
I have no idea why I'm getting this following error: Control cannot fall through
I have absolutely no idea why this is happening but the following code seems

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.