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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T11:55:27+00:00 2026-06-08T11:55:27+00:00

I have a number of C++ files distributed in several folders. a_library/ file1.cpp file2.cpp

  • 0

I have a number of C++ files distributed in several folders.

a_library/
    file1.cpp
    file2.cpp
    category1/
        file3.cpp
        file4.cpp

They are guaruanteed to be uniquely named. I want to compile all those C++ files to seperate Object-files in the obj/ directory.

I have a list of all source-files with relative path, and their corresponding destination-names.

a_library/file1.cpp
a_library/file2.cpp
a_library/category1/file3.cpp
a_library/category1/file4.cpp

obj/file1.obj
obj/file2.obj
obj/file3.obj
obj/file4.obj

How can I make a rule that will convert a C++ file from the first list to a object-file from the second one?

These attempts do not work:

obj/%.obj: %:cpp
    # ...

%.obj: %.cpp
    # ...

.cpp.obj:
    # ...

I would like to not write rules like this:

obj/%.obj: a_library/%.cpp
    # ...

obj/%.obj: a_library/category1/%.cpp
    # ...
  • 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-08T11:55:28+00:00Added an answer on June 8, 2026 at 11:55 am

    Try setting VPATH:

    VPATH = a_library:a_library/category1
    obj/%.o: %.cpp
        $(CXX) -c $(CPPFLAGS) $(CFLAGS) $(CXXFLAGS) -o $@ $<
    

    And to add complete file list (I would recommend you explicitely list the files, do not use $(wildcard ...) function) and linking of the application:

    files := main.cpp $(wildcard a_library/*.cpp) a_library/category1/file.cpp
    
    obj/application: $(patsubst %.cpp,obj/%.o,$(notdir $(files)))
        $(CXX) $(CFLAGS) $(CXXFLAGS) $(LDFLAGS) -o $@ $+
    

    The $(wildcard) has an annoying tendency to pick up anything in the directories, like one-off test files or temporaries (if they happen to have a fitting name: ~file.cpp).

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

Sidebar

Related Questions

When I use javascript_include_tag or stylesheet_link_tag to include files, they have a number at
I have number of cpp files in unmanaged c++ , I want to access
I have a number of files I am loading into a slideshow, I have
I have a number of source files I want to agglomerate into a .a
I have a number of data files to process from a data warehouse that
I have a number of .css files spread across some directories. I need to
I have a number of ~10MB xml files on a local computer. For each
I have a large number of csv files that look like this below: xxxxxxxx
I have a number of large data files that I included in projects attributed
Hi i have requirement to process large number of files via multithreading in java.

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.