制作由GCC编译的对象文件(*。O)为二进制文件(*。bin)
我正在学习OS教程。 https://github.com/cfenollosa/cfenollosa/os-tutorial 我使用GCC将我的basic.C转换为基本。
gcc -ffreestanding -c basic.c -o basic.o
如在Toturial中所描述的那样, 根据下一步,我需要将basic.O转换为basic.bin。
ld -o basic.bin -Ttext 0x0 --oformat binary basic.o
问题是我的平台是MacBook Pro(M1)哪个OS版本为12.4。
MacOS LD和Windows LD之间似乎存在差异。
如果我输入ld -o basic.bin -ttext 0x0 -oformat二进制basic.o
,我将获得以下反馈。
ld: unknown option: -Ttext
关于ld
,我需要将Basic..O转换为我的平台上的BASIC.BIN的命令?
I am learning the os tutorial.
https://github.com/cfenollosa/os-tutorial
After I using gcc convert my basic.c to basic.o,
gcc -ffreestanding -c basic.c -o basic.o
As describe in the toturial, I get a file named basic.o which is an object file.
According to the next step, I need to convert basic.o to basic.bin.
ld -o basic.bin -Ttext 0x0 --oformat binary basic.o
The question is that my platform is Macbook Pro(M1) which os version is 12.4.
It seems that there are differences between macos ld and windows ld.
If I input ld -o basic.bin -Ttext 0x0 --oformat binary basic.o
, I will get feedback as below.
ld: unknown option: -Ttext
What command about ld
I need to convert basic.o to basic.bin on my platform?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
是的,它们是不同的,实际上,除非明确安装并另有说明,否则GCC将只是Clang的同一链接。
至于-t选项,我不太确定您是否知道它的含义(如果不知道,它基本上会告诉链接器将文本部分放在地址0x0上)。
您可能需要花费时间并寻找如何构建LinkerScript,因为无论如何您可能会以后使用它。
链接在某个时候已经死了,您只需Google“ Linkerscript Ld”,它将显示一些教程。
Yes they are different, in fact gcc will be just a symlink to clang unless explicitly installed and told otherwise.
As for the -T option, I'm not too sure if you know what it means(if you don't, it will basically tell the linker to put the text section at address 0x0).
You might want to invest the time and look for how to build a linkerScript because you will probably going to use that later anyway.
How to build a linkerScript
If the link is dead at some point, you can just google "linkerScript ld" and it will show some tutorials.