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 frequently have some code that should be run either on a schedule or
I do NOT have python/ruby enabled. My Question: I frequently have to write things
I frequently run into the problem that I have to preserve state between several
I have a function that I use quite frequently, which allows me to write
I frequently have svn-based projects that include third-party components such as the TinyMCE (in-browser
Why can't open generic types be passed as parameters. I frequently have classes like:
As a web developer I frequently will have two floated (child) divs inside of
I have a table of frequently updated information. This is presented using a container
I have two commands I execute frequently. Let's say the first is 'abcd' and
I have an application that makes use of frequently updated lists. So for example,

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.