VxWorks中tornado2.2中的编译器支持哪个C语言标准,有哪些标准库?

通过观察tornado2.2的安装目录,我们可以发现其编译器所在目录。

image-20210704094736375

这和我们在电脑上安装的MinGW的安装目录内容几乎是一致的,下面图片是我在Win10上安装的MinGW

image-20210704094856917

在该目录下搜索发现,有g++,gdb.make等gnu常用工具链

image-20210704095429885

image-20210704095458497

image-20210704095530058

可以看出tornado上的编译器工具都是在标准GCC上进行了一些改编,至于和标准GCC有哪些不同,这个暂时我也不知道。

下面我们就要弄清楚该GCC是基于哪个版本的了?

下面是不同GCC版本对C语言和C++的支持情况了

GCC 版本C语言常用标准
C89/C90C99C11C17GNU90GNU99GNU11GNU17
10.1 ~ 8.4c89 / c90c99c11c17/c18gnu90/gnu89gnu99gnu11gnu17/gnu18
7.5 ~ 5.5c89/c90c99c11gnu90/gnu89gnu99gnu11
4.9.4 ~ 4.8.5c89/c90c99c11gnu90/gnu89gnu99gnu11
4.7.4c89/c90c99(部分支持)c11(部分支持)gnu90/gnu89gnu99(部分支持)gnu11(部分支持)
4.6.4c89/c90c99(部分支持)c1x(部分支持)gnu90/gnu89gnu99(部分支持)gnu1x(部分支持)
4.5.4c89/c90c99(部分支持)gnu90/gnu89gnu99(部分支持)

注意,表头表示的是各个编译标准的名称,而表格内部的则为 -std 可用的值,例如 -std=c89、-std=c11、-std=gnu90 等(表 2 也是如此)。

表 2 罗列了常用的 GCC 版本对 C++ 程序编译标准的支持程度。

GCC 版本C++常用标准
C++98/03C++11C++14C++17GNU++98GNU++11GNU++14GNU++17
10.1 ~ 8.4c++98/c++03c++11c++14c++17gnu++98/gnu++03gnu++11gnu++14gnu++17
7.5 ~ 5.5c++98/c++03c++11c++14c++1z(部分支持)gnu++98/gnu++03gnu++11gnu++14gnu++1z(部分支持)
4.9.4 ~ 4.8.5c++98/c++03c++11c++1y(部分支持)gnu++98/gnu++03gnu++11gnu++1y(部分支持)
4.7.4c++98c++11(部分支持)gnu++98gnu++11(部分支持)
4.6.4c++98c++0x(部分支持)gnu++98gnu++0x(部分支持)
4.5.4c++98c++0x(部分支持)gnu++98gnu++0x(部分支持)

表 1、2 中,有些版本对应的同一编译标准有 2 种表示方式,例如对于 8.4~10.1 版本的 GCC 编译器来说,-std=c89 和 -std=c90 是一样的,使用的都是 C89/C90 标准。另外,GCC 编译器还有其他版本,读者可查阅 GCC文档获得相关信息。

在GCC官网上有比这更全的版本说明,考虑到VxWorks5.5还是很久之前的操作系统,因此其GCC版本不可能会很高。

GCC版本说明:GCC online documentation

通过将编译器目录下的bin目录加入环境变量(安装过MINGW的应该对这个很熟),我们可以通过命令行来查看GCC版本。
image-20210704102131768
image-20210704102151655
image-20210704102216983
image-20210704102237992

可以看到g++simpc和g++pentium的GCC版本显示都是gcc-2.96

通过查询得知,gcc-2.96是一个开发版,而不是一个稳定发行版。

GCC 3.0是一项重大工作,涉及对GCC 2.95的ABI更改。由于“GCC 2.96”基于GCC 3.0开发的快照,因此ABI可能会不断变化,您将使用开发快照作为生产编译器会产生副作用。

因此个人猜测就是windriver把当时的GCC3.0开发的快照拿去进行改编了。

在网上也找到了GCC官网发的对gcc-2.96的一个说明。

GCC 2.96

October 6th, 2000

It has come to our attention that some GNU/Linux distributions are currently shipping with ``GCC 2.96''.

We would like to point out that GCC 2.96 is not a formal GCC release nor will there ever be such a release. Rather, GCC 2.96 has been the code- name for our development branch that will eventually become GCC 3.0.

Current snapshots of GCC, and any version labeled 2.96, produce object files that are not compatible with those produced by either GCC 2.95.2 or the forthcoming GCC 3.0. Therefore, programs built with these snapshots will not be compatible with any official GCC release. Actually, C and Fortran code will probably be compatible, but code in other languages, most notably C++ due to incompatibilities in symbol encoding (``mangling''), the standard library and the application binary interface (ABI), is likely to fail in some way. Static linking against C++ libraries may make a binary more portable, at the cost of increasing file size and memory use.

To avoid any confusion, we have bumped the version of our current development branch to GCC 2.97.

Please note that both GCC 2.96 and 2.97 are development versions; we do not recommend using them for production purposes. Binaries built using any version of GCC 2.96 or 2.97 will not be portable to systems based on one of our regular releases.

If you encounter a bug in a compiler labeled 2.96, we suggest you contact whoever supplied the compiler as we can not support 2.96 versions that were not issued by the GCC team.

Please see https://gcc.gnu.org/snapshots.html if you want to use our latest snapshots. We suggest you use 2.95.2 if you are uncertain.

重点在这句话Actually, C and Fortran code will probably be compatible, but code in other languages, most notably C++ due to incompatibilities in symbol encoding (``mangling’’), the standard library and the application binary interface (ABI), is likely to fail in some way.

所以在VxWorks5.5上还是乖乖用C语言吧,就别想着用C++了,等下出了问题都不知道是哪里出了问题。

那gcc2.6应该是支持C89/C90的,但是是否支持C99呢?

默认的编译命令参数为

-g -mpentium -ansi -fno-builtin -fno-defer-pop -I. -IC:/Tornado2.2/target/h/ -DCPU=SIMNT -DTOOL_FAMILY=gnu -DTOOL=gnu

当我们将 -ansi 改成 -std = c99 时,会报错,如下图所示

image-20210704115815517

当我们将 -ansi 改成 -std = c89 时,不会报错,可以正常编译,如下图所示

image-20210704120100791

通过上面我们可以看出,该编译器只支持C89标准的。

其实我们还可以通过一个特别简单的程序来验证编译器是否支持C99。

大家应该都知道对于C89/C90标准的编译器是不支持在for循环中定义变量的,测试代码如下

int main(void) {
	for(int i = 0; i < 5; i++){
		;
	}
     return 0;
}

所以编译会发生报错

image-20210704120854795

代码改成下面这样就可以正常编译了

int main(void) {
	int i;
	for(i = 0; i < 5; i++){
		;
	}
     return 0;
}

image-20210704121021243

另外,编译器命令参数那里,我们使用了-ansi 参数,该参数与 -std = c89是等价的,都不支持双斜线注释(//)。

image-20210704121901330

这篇文章说了一下这个问题:如何使GCC能够处理双斜线注释(C++风格注释)?

我们改为-std=gnu89是不行的,不支持。

试了下 -lang-c-c+±comments ,发现是可以的,只是会报一个提示

image-20210704123016949

但是程序是可以download进模拟机并正常运行的。


那这个编译器是否支持所有的标准库呢?

C语言标准库有十五个

image-20210704111733778

通过下面一段代码来测试一下

#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
#include <ctype.h>
#include <errno.h>
#include <limits.h>
#include <locale.h>
#include <math.h>
#include <setjmp.h>
#include <stdarg.h>
#include <stddef.h>
#include <string.h>
#include <time.h>

int main() {
	printf("hello world\n");
	return 0;
}

发现可以正常通过编译,说明这些头文件都是存在的。

image-20210704111922829

其实通过上面编译器的命令我们也可以看出很多信息,在此就不赘述了。

这边找到一篇说明的文章:Tornado编译vxworks本质及过程

我们可以找到项目下的makefile,内容如下

# Makefile generated by the project manager
#


## core information

PRJ_FILE       = teststructlib.wpj
ifeq ($(wildcard Makefile),)
PRJ_DIR        = ..
else
PRJ_DIR        = .
endif
PRJ_TYPE       = vxApp
PRJ_OBJS       = main.o
BUILD_SPEC     = SIMNTgnu
TGT_DIR        = $(WIND_BASE)/target




## build-configuration info

ifeq ($(BUILD_SPEC),SIMNTgnu)
CPU              = SIMNT
TOOL             = gnu
TOOL_FAMILY      = gnu
DEFAULT_RULE     = teststructlib.out
endif

include $(TGT_DIR)/h/make/defs.project

## build-configuration info

ifeq ($(BUILD_SPEC),SIMNTgnu)
AR               = arsimpc
AS               = ccsimpc
CC               = ccsimpc
CC_ARCH_SPEC     = -mpentium
CFLAGS           = -g -mpentium -ansi -fno-builtin -fno-defer-pop -I. -I$(WIND_BASE)/target/h/ -DCPU=SIMNT -DTOOL_FAMILY=gnu -DTOOL=gnu
CFLAGS_AS        = -g -mpentium -ansi -fno-builtin -fno-defer-pop -P -xassembler-with-cpp -I. -I$(WIND_BASE)/target/h/ -DCPU=SIMNT -DTOOL_FAMILY=gnu -DTOOL=gnu
CPP              = ccsimpc -E -P
LD               = ldsimpc
LDFLAGS          = --subsystem=windows
LD_PARTIAL       = ccsimpc -r -nostdlib
LD_PARTIAL_FLAGS = -r
NM               = nmsimpc -g
OPTION_DEFINE_MACRO = -D
OPTION_DEPEND    = -M -w
OPTION_GENERATE_DEPENDENCY_FILE = -MD
OPTION_INCLUDE_DIR = -I
OPTION_LANG_C    = -xc
OPTION_UNDEFINE_MACRO = -U
SIZE             = sizesimpc
TOOL_FAMILY      = gnu
POST_BUILD_RULE  = 
PRJ_LIBS         = 
endif

# override make definitions only below this line


# override make definitions only above this line
include $(TGT_DIR)/h/make/rules.project



## build-configuration info

ifeq ($(BUILD_SPEC),SIMNTgnu)
main.o:
	$(CC) -g -mpentium -ansi -fno-builtin -fno-defer-pop -I. -I$(WIND_BASE)/target/h/ -DCPU=SIMNT -DTOOL_FAMILY=gnu -DTOOL=gnu -c $(PRJ_DIR)/../layermodel/main.c
endif


## dependencies

main.o: $(PRJ_DIR)/../layermodel/main.c \
	$(WIND_BASE)/host/$(WIND_HOST_TYPE)/lib/gcc-lib/i386-pc-mingw32/gcc-2.96/include/stddef.h \
	$(WIND_BASE)/host/$(WIND_HOST_TYPE)/lib/gcc-lib/i386-pc-mingw32/gcc-2.96/include/stdarg.h


## user defined rules

嗯嗯,就酱,下篇文章应该就是关于GCC和makefile的了,敬请期待!

  • 2
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

小熊coder

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值