簡體   English   中英

如何創建一個Linux Shell別名來給g ++編譯器要編譯的文件路徑?

[英]how to create a linux shell alias to give to g++ compiler the path of the file to compile?

我要做的是為下面的句子創建別名:

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

因為我必須經常編譯單個文件。

為此,我正在嘗試使用輸出文件名和要編譯的文件路徑創建一個txt文件。 因此,我有一個名為tocompile.txt的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.

什么是正確的方法?

是否

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

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

但是,正如我在評論中已經提到的那樣,我將為此工作推薦一個簡單的Makefile。 使用內容創建一個名為Makefile的文件

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

然后運行make 查看教程,例如教程。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM