I am trying to compile a simple "asm" file with GCC to understand the compilation. test.h:
#define APPLICATION_EXIT .end
test.asm:
#include "test.h"
APPLICATION_EXIT
when I run :
arm-none-eabi-gcc-9.2.1.exe -mcpu=cortex-m7 -mthumb -g -c .\test.asm
I got :
arm-none-eabi-gcc-9.2.1.exe: warning: .\test.asm: linker input file unused because linking not done
but there is nothing generated , no "out' file. I try to run
arm-none-eabi-as -mcpu=cortex-m7 -mthumb -g -c .\test.asm
I got :
.\test.asm: Assembler messages:
.\test.asm:2: Error: bad instruction `application_exit'
It looks like the AS works but the Macro doesn't work. when I change the test.asm to :
#include "test.h"
.end
arm-none-eabi-as -mcpu=cortex-m7 -mthumb -g -c .\test.asm
works. I got a.out.
Did I use GCC wrong? whey Gcc is not able to run the backend "as" directly? Why the #define Macro doesn't work? Thank you so much, I appreciate any comments.
You can see in the gcc manual which filename extensions are recognized.
.asm
is not listed as assembly language source files in Unix are traditionally named.s
, or.S
(capital S, remember Unix filenames are case sensitive) if they are to be passed through the C preprocessor. (C-style macro and include expansion are handled by the C preprocessor, not by the assembler itself, which is why it doesn't work when you runas
directly.)Files not otherwise recognized are assumed to be object files to be passed to the linker, but since you specified
-c
, the linker is not to be run, sogcc
thinks there is nothing to do.You can either rename your file to end in
.S
, or use the option-x assembler-with-cpp
to explicitly tell gcc what to do with this file. Or, you can first runcpp
on your file to expand the macros and includes, and then runas
on the resulting output (or pipe one into the other).