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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T09:20:54+00:00 2026-05-12T09:20:54+00:00

I have to frequently compile small program and run it. Since, it was tedious

  • 0

I have to frequently compile small program and run it. Since, it was tedious to write compile command g++ -W -Wall file.cpp -o out everytime for each cpp file, I wrote one small scripts, which does the compiling.

Here is the script that I wrote

#!/bin/bash
g++ -W -Wall $1 -o $1.out

So, if I have to compile file.cpp, I will do compile file.cpp and it will create file.cpp.out executable for me.
And, such file.cpp dont have any header files or any other dependencies.

I know how to write makefile for particular file.cpp like this (very simple case)

file: file.cpp
    g++ -W -Wall file.cpp -o file

but if I have to compile file2.cpp, I have to change above makefile again or write new. So, what I want to do is, when I give make file.cpp command it will produce file as executable. And when I give make file2.cpp it will produce file2 as executable, and similarly for other cpp files.

  • 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-12T09:20:54+00:00Added an answer on May 12, 2026 at 9:20 am
    export CXXFLAGS="-W -Wall"
    rm Makefile
    make file1
    

    Make has sane defaults. You don’t have to write a makefile to use make.

    Make has a set of generic rules, which get apply automatically when there is no specific rule. One of them is to make ‘file’ out of ‘file.cpp’ using a C++ compiler with flags from environment variable CXXFLAGS. This works a bit like you want…

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

Sidebar

Related Questions

I have a .csv file that is frequently updated (about 20 to 30 times
I have a few batch files I need to run frequently in developing a
I frequently have problems dealing with DataRows returned from SqlDataAdapters . When I try
We frequently have users that create multiple accounts and then end up storing the
I am posting a very simple form using a method I have used frequently
I am writing Eclipse plugins, and frequently have a situation where a running Job
I have an error occuring frequently from our community server installation whenever the googlesitemap.ashx
I have a 'foreach' macro I use frequently in C++ that works for most
I have heard this concept used frequently, but I don't have a really good
I have a stored procedure currently executing a complicated fetch that is frequently timing

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.