Reputation:
I want to see the assembly version of my C
code and I've learned that -S
option can show it but I get this error when using that option:
cannot specify -o with -c, -S or -E with multiple files
The only compiler options I have used besides that one are: -m64
and -Wfatal-errors
. I use the Codebloc::Blocks
IDE and mingw64
compiler. The source file is a43.c
and I inserted the option in this place:
Am I doing it right? I prefer using the GUI instead of command line.
Upvotes: 1
Views: 5751
Reputation: 61317
The compiler options:
-c # compile only (don't link)
-S # assemble only (don't compile or link)
-E # preprocess only (don't assemble, compile or link)
are mutually exclusive. Furthermore, you cannot specify:
-o foo.o # write output to `foo.o`
if you are specifying multiple input source files.
You are adding -S a43.c
to the Other compiler options. That means you
are adding them to the existing compilation options for your project. Those
options already include -c
by default, because that's the option to compile,
so adding -S
conflicts with -c
.
-S
does not take any argument, specifically no filename argument. It tells
gcc
only to assemble (not compile or link) the input files, whatever they are. So adding:
-S a43.c
as well as adding -S
to the existing options, adds an input file,
a43.c
, to the project's compiler options. But of course Code::Blocks will add the
name of an input file to the compiler options whenever it compiles one of the
files in the project. So there will be two source filenames in the commandline.
Hence the error:
cannot specify -o with -c, -S or -E with multiple files
If you want to modify your Code::Blocks compilation options so that they will also produce the assembly listing of each file compiled, then remove
-S a43.c
from Other compiler options and replace it with
-save-temps
Then, whenever gcc compiles a file foo.c
in the project, it will save the
intermediate files as:
foo.s # The assembly
foo.i # The preprocessed source
These files will be saved in the same directory as foo.c
itself; not in the
directory where the object file foo.o
is output.
See the documentation of -save-temps
in the GCC manual
Upvotes: 2
Reputation: 9
If you are on Linux, You can make use of the gcc to compile the code, and objdump -M intel -D a.out where a.out is your compile code, and the -M intel is to output into intel syntax or remove the -M intel. But you can also make use of gcc -S code.c -o asm_code in other to see the assembly language output.
Upvotes: 0