创建一个 bash 脚本来编译一个 C++
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/29090372/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Creating a bash script to compile a c++
提问by Leor Roynsky
I have a program I've written in c++ which outputs some simulation results to a .csv excel file.
我有一个用 C++ 编写的程序,它将一些模拟结果输出到 .csv excel 文件。
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).
根据一些说明,我需要创建一个简单的 bash 脚本,该脚本将在给定命令“$ run_program”($ 不是命令的一部分)的情况下运行 .cpp 文件。
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.
我查看了 Stackoverflow 和其他网站,但是我没有找到一个具体的答案来帮助我。如果回答者能花一些时间解释参数的含义,我也将不胜感激。
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.
这是我看过的链接之一,但是我无法从中做出正面或反面。
回答by Osama Bin Omar
i dont know the command you are using to compile your c++ program but this might help you.
我不知道您用来编译 C++ 程序的命令,但这可能对您有所帮助。
- Create a file with ".sh" extension and open it with your favorite text editor.
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
Now you need to run this script, To do this open a terminal
chmod u+x scriptname.sh
- 创建一个扩展名为“.sh”的文件,并使用您喜欢的文本编辑器打开它。
粘贴此代码(使用您用来编译程序的行更改编译行)
#!/bin/bash #Run this in terminal #+ Command to compile c++ program. here i used common one g++ filename.cpp -o anyname exit 0
现在你需要运行这个脚本,为此打开一个终端
chmod u+x 脚本名.sh
Then run the script by ./scriptname.sh
Hopefully this will compile your program.
然后运行脚本./scriptname.sh
希望这将编译您的程序。