我正在编写 Makefile 并设置 Docker 映像以在 CI 环境中进行构建。在这些不同的脚本中,我想打印我正在设置和/或使用的工具的版本。
gcc --version显示简单的版本号以及一些版权和许可信息。我的机器上的示例输出:
$ gcc --version
gcc.exe (x86_64-posix-seh-rev0, Built by MinGW-W64 project) 8.1.0
Copyright (C) 2018 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
Run Code Online (Sandbox Code Playgroud)
有没有更简单的方法来获取版本信息而不解析此输出?
这里有两个想法:
-dumpversion选项代替。它应该打印一个漂亮、简洁的版本号。适用于任何平台,无需进一步解析。$ gcc -dumpversion
8.1.0
$ arm-none-eabi-gcc -dumpversion
8.3.1
Run Code Online (Sandbox Code Playgroud)
编辑 2021 年 1 月 17 日:
我最近发现在早期的 GCC 版本上-dumpversion只显示主要版本,并-dumpfullversion打印所有 Major.Minor.Patch 版本号。因此-dumpfullversion,如果上述方法对您不起作用,请尝试一下。
head抓住第一行$ gcc --version | head -n1
gcc.exe (x86_64-posix-seh-rev0, Built by MinGW-W64 project) 8.1.0
$ arm-none-eabi-gcc --version | head -n1
arm-none-eabi-gcc.exe (GNU Tools for Arm Embedded Processors 8-2019-q3-update) 8.3.1 20190703 (release) [gcc-8-branch revision 273027]
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
534 次 |
| 最近记录: |