Creating a bash script to compile a c++

血红的双手。 提交于 2019-12-13 10:36:23

问题


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.


回答1:


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.




回答2:


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



来源:https://stackoverflow.com/questions/29090372/creating-a-bash-script-to-compile-a-c

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!