如何创建一个linux shell别名给g ++编译器编译的文件路径?

问题描述 投票:1回答:1

我想要做的是为下面的句子创建一个别名:

g++ -g -pedantic -Wall -o executablefilenamehere pathoffiletocompilehere

因为我必须经常编译单个文件。

为此,我正在尝试使用输出文件名和要编译的文件的路径创建一个txt文件。所以我有一个txt,名为tocompile.txt,文件包含:

test /home/me/test.cpp

然后,我分配给一个var,我称之为tocompile.txt的内容:

tocompile=`cat tocompile.txt`

这是有效的,因为如果我回复$ 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.

这样做的正确方法是什么?

linux bash shell g++
1个回答
0
投票

是否

alias gxxcomp='g++ -g -pedantic -Wall -o `cat tocompile.txt`'

为你工作?至少在我的bash版本中有效。

但正如我在评论中已经提到的,我会为这项工作推荐一个简单的Makefile。使用内容创建名为Makefile的文件

test: test.cpp
        g++ -g -pedantic -Wall -o $@ $<

并运行make。查看教程,例如this one

© www.soinside.com 2019 - 2024. All rights reserved.