How to generate assembly listings in Code::Blocks?
c, codeblocks, gcc
Solution
I presume you want your Code::Blocks build to generate an annotated assembly listing for each `.c` source file compiled.
Yes, you can do this as follows (as of Code::Blocks 12.11):
- In the Code::Blocks IDE, navigate Settings -> Compiler
- Ensure that the Selected compiler is GCC.
- In the tab list that begins Compiler settings, Linker settings..., navigate to the last tab, Other settings.
- In the Other settings pane, select Advanced options, at the bottom right.
- In the Advanced compiler options windows, ensure that the drop-down menu entitled Command is set at Compile single file to object file
See the edit box entitled Command line macro and confirm that it contains the line:
$compiler $options $includes -c $file -o $object
To this line append a space followed by exactly this:
-Wa,-alhds=$objects_output_dir$file_name.list
(Do not allow yourself to be misled at this point by the listing of Command macros at the left of the window. If it lists `$objectsoutputdir` instead of `$objects_output_dir` and `$filename` instead of `$file_name`, it is wrong.)
- Click `OK` in the Advanced compiler options window and then in the Compiler settings window.
- Rebuild your project.
The effect of the change you have made to the global compiler settings is that the options:
-alhds=$objects_output_dir$file_name.list
will be passed to the assembly phase when compiling each source file `filename.c`, with `$objects_output_dir`replaced by the object output files directory of your project and `$file_name` replaced by `filename`, causing the assembler to generate an annotated listing file `filename.list` in the same directory where `filename.o` is placed.
Unfortunately I do not see how to do this just for a selected project; so after the change the compiler will generate the `.list` files for all projects.
If this is a nuisance, you can work around it by first configuring a "new compiler" in Code::Blocks that is a copy of GCC, with whatever name you like, and then applying the change I have described to this copy. To do this:
- Navigate Settings -> Compiler;
- Ensure the Selected compiler is GCC
- Select Copy and enter the name of your choice when prompted, e.g. "gcc-list"
Problem
Can we generate an assembly file in code-blocks for C programs, the same way we can generate listing file when we write C-code for micro-controller?