Leor Roynsky
Leor Roynsky

Reputation: 37

Creating a bash script to compile a c++

I have a program I've written in c++ which outputs some simulation results to a .csv excel file.

According to some instructions I need to create a simple bash script that would run the .cpp file given the command "$ run_program" ($ is not a part of the command).

I've looked on Stackoverflow and other sites however I have not found a concrete answer to help me. I would also greatly appreciate it if those who answer can take some time to explain what the parameters mean.

Thank you.

How I should make a bash script to run a C++ program?

This is one of the links I've looked at, however I could not make heads or tails out of this.

Upvotes: 1

Views: 20621

Answers (2)

StackAttack
StackAttack

Reputation: 1219

It sounds like a Makefile is what you are looking for here. Definitely worth getting a handle on if you deal with programming.

Upvotes: 0

Osama Bin Omar
Osama Bin Omar

Reputation: 116

i dont know the command you are using to compile your c++ program but this might help you.

  1. Create a file with ".sh" extension and open it with your favorite text editor.
  2. Paste this code (change compiling line with line you are using to compile your progam)

    #!/bin/bash
    #Run this in terminal
    #+ Command to compile c++ program. here i used common one
    g++ filename.cpp -o anyname
    exit 0
    
  3. Now you need to run this script, To do this open a terminal

    chmod u+x scriptname.sh

Then run the script by ./scriptname.sh Hopefully this will compile your program.

Upvotes: 8

Related Questions