How do I enable the preprocessor in gcc assembly

二次信任 提交于 2019-12-11 03:25:53

问题


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?


回答1:


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).



来源:https://stackoverflow.com/questions/27993384/how-do-i-enable-the-preprocessor-in-gcc-assembly

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!