如何在gcc程序集中启用预处理器 [英] How do I enable the preprocessor in gcc assembly
本文介绍了如何在gcc程序集中启用预处理器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
gcc -std = gnu99 -fno-leading-underscore -m32 -c -o obj / entry.o src / entry.s
但是,当我编译链接器时说:
ld -melf_i386 -T kernel.ld -o kernel obj / entry.o obj / init.o
obj /entry.o:(multiboot+0x0):对'MB_MAGIC'的未定义引用
obj / entry.o :(多引导+ 0x4):对'MB_FLAGS'的未定义引用
obj / entry.o :( multiboot + 0x8):对'MB_CHECKSUM'的未定义引用
这些引用在entry.s文件中定义使用预处理器:
#define MB_MAGIC 0x1badb002
#define MB_FLAGS 0x0
#define MB_CHECKSUM - (MB_MAGIC + MB_FLAGS)
如何启用预处理?
解决方案
正如 gcc的文档,如果文件na我以大写 .S
结尾,它将被自动预处理。您可以添加 -v
选项来查看gcc遵循的步骤。如果你不想改变文件名,你也可以用 -x汇编程序与cpp
来指定语言(在文件名之前)。
I am using the GCC like this:
gcc -std=gnu99 -fno-leading-underscore -m32 -c -o obj/entry.o src/entry.s
However, when I compile the linker says:
ld -melf_i386 -T kernel.ld -o kernel obj/entry.o obj/init.o
obj/entry.o:(multiboot+0x0): undefined reference to `MB_MAGIC'
obj/entry.o:(multiboot+0x4): undefined reference to `MB_FLAGS'
obj/entry.o:(multiboot+0x8): undefined reference to `MB_CHECKSUM'
Those references are defined in the entry.s file with the preprocessor:
#define MB_MAGIC 0x1badb002
#define MB_FLAGS 0x0
#define MB_CHECKSUM -(MB_MAGIC + MB_FLAGS)
How can I enable preprocessing?
解决方案
As explained in gcc's documentation, if the file name ends in capital .S
, it will be preprocessed automatically. You can add the -v
option to see what steps gcc follows. If you don't want to change the file name, you can also specify the language with -x assembler-with-cpp
(before the file name).
这篇关于如何在gcc程序集中启用预处理器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文