我想做的是为下面的句子创建一个别名:
g++ -g -pedantic -Wall -o executablefilenamehere pathoffiletocompilehere
因为我必须经常编译单个文件。
要这样做,我正在尝试使用输出文件名创建一个TXT文件和文件的路径要编译。因此,我有一个称为tocompile.txt的txt,其中包含:
test /home/me/test.cpp
然后,我分配给我称之为tocompile.txt的内容的var:
tocompile=`cat tocompile.txt`
这是在工作,因为如果我做echo $ tocompile,我会得到:test/home/me/test.cpp
所以,我正在尝试创建别名:
alias gxxcomp='g++ -g -pedantic -Wall -o $tocompile'
当我这样做时它不起作用:
gxxcomp
我得到:
g++: error: missing filename after ‘-o’
g++: fatal error: no input files
compilation terminated.
正确的方法是什么?
做
alias gxxcomp='g++ -g -pedantic -Wall -o `cat tocompile.txt`'
为您工作?至少在我有效的bash版本中。
但是,正如我在评论中已经提到的那样,我建议为这项工作提供一个简单的makefile。创建一个名为 makefile 的文件
test: test.cpp
g++ -g -pedantic -Wall -o $@ $<
和运行 make 。查看一个教程,例如,此。