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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T16:18:36+00:00 2026-05-31T16:18:36+00:00

I am now studying C++. I want a makefile which will compile all of

  • 0

I am now studying C++. I want a makefile which will compile all of the cpp files in the current directory to separate executables. For example:

In a directory there are 3 c++ files, such as examp1.cpp, examp2.cpp and examp3.cpp. I want a makefile which will compile and link them and give examp1.exe, examp2.exe and examp3.exe

I have created a bash script to compile all of them and create exes but I think; that’s not the exact way to do this.

I have a a Makefile for “.c”, but that does not seem to work here. It is only creating object files and not actually linking it. It is as follows:

SRCS=$(wildcard *.c)
OBJS=(SRCS:.c=.o)
all: $(OBJS)

The above code compiles all the new and modified “.c” files to “.o” files with same name in the current directory.

The bash script I am using to create executables is as follows:

for i in ./*.cpp
do
   g++ -Wno-deprecated $i -o `basename $i .cpp`".exe"
done

This means I want whatever “.cpp” files I put in that directory, by using a simple “make all” or anything like that it should compile.

  • 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-31T16:18:37+00:00Added an answer on May 31, 2026 at 4:18 pm

    A minimal Makefile that does what you want would be:

    #Tell make to make one .out file for each .cpp file found in the current directory
    all: $(patsubst %.cpp, %.out, $(wildcard *.cpp))
    
    #Rule how to create arbitary .out files. 
    #First state what is needed for them e.g. additional headers, .cpp files in an include folder...
    #Then the command to create the .out file, probably you want to add further options to the g++ call.
    %.out: %.cpp Makefile
        g++ $< -o $@ -std=c++0x
    

    You’ll have to replace g++ by the compiler you’re using and possibly adjust some platform specific setting, but the Makefile itself should work.

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

Sidebar

Related Questions

I'm studying Three20 now and want to implement facebook iphone client myself as a
I've been studying php for about 6 months now and want to start learning
I'm studying jquery and html5 canvas. All I want to do is a simple
i'm studying iOS programming. but i have a problem, which is opaque. now assume.
I'm studying inheritance and polymorphism now and I've came across the concept that the
I'm studying string searching algorithms now and wondering what algorithm is used for .NET
I've been studying OOP for quite a while now and I have a good
I have been studying unicode and its Python implementation now for two days, and
I have spent 1 week studying objective C. Now I am quite confused at
Since a month ago i am studying restful web services really hard. Now that

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.