如何使用 GCC 编译独立环境?
我正在处理的代码应该可以为托管环境和独立环境构建,为后一种情况提供一些 stdlib 函数的私有实现。
我可以在普通工作站/构建服务器上仅使用 GCC 进行可靠的测试吗? 使用 GCC 编译独立环境
“-ffreestand”选项看起来有希望,但似乎它“仅”禁用内置函数并正确设置 STDC_HOSTED 宏,它仍然提供所有系统标头。
选项“-nostdinc”限制太多;我仍然想使用独立实现所需的标头(特别是 stddef.h 和 limit.h)。
我在这里缺少什么?
哦,我目前使用的是 GCC 4.4.3,“很快”将升级到 4.5.0。
The code I'm working on is supposed to be possible to build for both hosted and freestanding environments, providing private implementations for some stdlib functions for the latter case.
Can I reliably test this with just GCC on a normal workstation/build server? Compile for freestanding environment with GCC
The "-ffreestanding" option looked promising, but it seems that it "only" disables built-ins and sets the STDC_HOSTED macro properly, it still provides all system headers.
The option "-nostdinc" is too restrictive; I still want to use the headers required for a freestanding implementation (in particular stddef.h and limits.h).
What am I missing here?
Oh, and I'm using GCC 4.4.3 for the moment, will upgrade to 4.5.0 "soon".
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
好吧,既然还没有给出答案,我不妨描述一下我是如何完成这项工作的。它非常简单,但根据目标系统的不同,它可能会很乏味。
使用“-nostdinc”意味着将跳过标准系统包含路径;当然,仍然会搜索用“-I”给出的其他包含路径来查找标头。
因此,对于独立构建目标,我创建一个文件夹“include-freestand-c89”并链接相关的系统头文件 - float.h、iso646.h、 >limits.h、stdarg.h 和 stddef.h —— 那里。其他标头可能包含在其中,具体取决于您的平台,因此您可能需要进行一些研究并设置更多链接(因此,如果您需要对多个目标平台执行此操作,则会很乏味)。
然后,C89 目录可以用作“include-freestand-c99”的基础,要链接的额外标头是 stdbool.h 和 stdint.h
命令行那么使用是
或者
Well, since no answer is given yet I'd might as well describe how I made this work. It's pretty simple although depending on the target system it can be tedious.
Using "-nostdinc" means that the standard system include paths will be skipped; other include-paths given with "-I" will of course still be searched for headers.
So, for the freestanding build target I create a folder 'include-freestanding-c89' and link the relevant system headers -- float.h, iso646.h, limits.h, stdarg.h and stddef.h -- there. Other headers might be included in these, depending on your platform, so you might have to do some research and set up more links (hence the tediousness if you need to do this for several target platforms).
The C89 directory can then be used as base for 'include-freestanding-c99', the extra headers to link are stdbool.h and stdint.h
The command-line to use is then
or
这个 Xen
Makefile
使用gcc -print-search-dirs
来获取带有stddef.h
的目录,类似的,用- 添加它isystem
,然后使用-nostdinc
构建:https://github.com/mirage/xen/blob/2676bc915157ab474ee478d929b0928cf696b385/stubdom/Makefile#L35
This Xen
Makefile
usesgcc -print-search-dirs
to get the directory withstddef.h
and similar, adds it with-isystem
, then uses-nostdinc
to build:https://github.com/mirage/xen/blob/2676bc915157ab474ee478d929b0928cf696b385/stubdom/Makefile#L35