o circle circle.o circulararea.o /usr/lib/libncurses.a
然而,这种方式会导致获得的程序文件明显大于动态链接方式获得的程序文件。
19.3.4 独立程序
除
GCC
命令行中所指定的对象文件和链接库文件以外,链接器还必须链接系统专用的
启动码(
startup code
),程序需要启动码才能被加载,并与操作系统进行顺利交互。
启动码位于标准对象文件
crt0.o
中,其中包含了可执行文件实际的进入点(
crt
代表“
C
runtime
”)。在大多数系统中,
GCC
也会默认地链接对象文件
crtbegin.o
和
crtend.o
中的
初始化与清理子程序。
然而,如果正在编写一个独立程序,例如操作系统或在嵌入式微控制器上执行的应
用,可以使用
-ffreestanding
和
-nostartfiles
选项,指示
GCC
不要链接启动码。使用
-nostdlib
选
项可以禁用自动链接到
C
标准链接库。如果使用该选项,必须为程序中所用
到的标准函数提供自己的版本。最后,在独立环境中,
C
程序不需要从
main()
开始。可
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month, and much more.
O’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
I wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
I’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
I'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.