在Windows PowerShell中为GCC设置别名

我正在尝试在Windows PowerShell中设置一个“gcc99”别名,它等于“gcc -std = C99 -pedantic -Wall”。 我们的想法是使用更少的击键来确保GCC以c99模式运行。 (我已尽力使以下post中的指南适应Windows PowerShell: 在GCC中设置std = c99标志

当我在设置这样的别名(下面的图1)后尝试编译时,我收到一个错误。 作为参考,如果我使用扩展命令进行编译,我不会收到此错误(参见下面的图2)。 作为测试,我尝试将gc99设置为“gcc”的别名(没有其他值)并且它工作正常(参见下面的3)。 请忽略我在代码中尚未解决的许多警告:)

有什么建议?

(我不确定为什么我的字幕没有出现在下面的图片中。我正在使用自动创建的图片格式,例如,对于第一张图片:“ 标题 ”后面跟着“ 1 :链接”下一行。)

图1:尝试通过设置为“gcc -std = c99 -pedantic -Wall”的“gcc99”别名进行编译时出错

图表2:通过“gcc -std = c99 -pedantic -Wall”直接编译时工作正常

图表3:通过设置为“gcc”的“gcc99”别名编译时工作正常,这让我觉得我在图表1中错误地设置了附加值

PowerShell中的别名与Unix shell中的别名不同。 您只能为cmdlet,函数或程序的名称添加别名,而不包括参数。 从Get-Help Set-Alias引用:

 NAME Set-Alias SYNOPSIS Creates or changes an alias (alternate name) for a cmdlet or other command element in the current Windows PowerShell session. SYNTAX Set-Alias [-Name] [-Value] [-Description ] [-Force] [-Option ] [-PassThru] [-Scope ] [-Confirm] [-WhatIf] [] DESCRIPTION The Set-Alias cmdlet creates or changes an alias (alternate name) for a cmdlet or for a command element, such as a function, a script, a file, or other executable . You can also use Set-Alias to reassign a current alias to a new command, or to change any of the properties of an alias, such as its description. Unless you add the alias to the Windows PowerShell profile, the changes to an alias are lost when you exit the session or close Windows PowerShell. 

使用默认参数集运行外部程序可以做的是将默认设置定义为数组并运行如下所示的程序:

 $CARGS = '-std=C99', '-pedantic', '-Wall' gcc $CARGS -more arguments here ... 

正如@ChrisN在下面的评论中建议的那样,如果您希望在所有PowerShell实例中预定义变量$CARGS ,则可以将其添加到自定义PowerShell配置文件 (例如,为用户提供%UserProfile%\Documents\WindowsPowerShell\profile.ps1 )。