News:

As usual while waiting for the next release - don't forget to check the nightly builds in the forum.

Main Menu

output file extension .bin/.hex

Started by anandamu16, March 03, 2017, 05:39:31 AM

Previous topic - Next topic

anandamu16

Hi,

I have recently started using codeblocks for embedded development. Whenever I make any project it gives the output file with extension .exe. I checked into project "properties->build targets" and realized that it gives the output extension bcz of the setting available here.
There are different types available here such as "Console Application", "Library static/dynamic", "GUI Application", "Commands only", "Native".
I want hex file as output which can be then run on embedded chip. So Can i do something like this:
- Select type as console application and set the output file extension as xxx.hex

Will it be ok?

Also is there any way to generate a .map file as output ?

christobal

Quote from: anandamu16 on March 03, 2017, 05:39:31 AM
So Can i do something like this:
- Select type as console application and set the output file extension as xxx.hex

Will it be ok?

No. How to get a hex file depends on the Compiler / Linker you use. For GCC, you need to build an "console application". This will generate an .elf File, which you have to convert to a HEX file in a post build step. You can use gcc objectcopy to accomplish this.

Quote from: anandamu16 on March 03, 2017, 05:39:31 AM
Also is there any way to generate a .map file as output ?

The linker usually provides a command line switch to produce a map file. Just add this to the linker options.

anandamu16

QuoteFor GCC, you need to build an "console application". This will generate an .elf File
I am getting .exe file only but no .elf, although I have checked Compiler flag to "produce debugging symbols [-d]" still I am getting .exe file
Quote.elf File, which you have to convert to a HEX file in a post build step. You can use gcc objectcopy to accomplish this.
(I am using GCC Compiler 5.3.0 on windows7)
I know there are pre/post build steps, but where to know about the post build steps, I mean what to enter.?
QuoteThe linker usually provides a command line switch to produce a map file. Just add this to the linker options.
Did you mean "Project->Build Options->Linker Settings ->Other Linker options"?

Commaster

#3
Quote from: anandamu16 on March 03, 2017, 11:42:46 AMI am getting .exe file only but no .elf, although I have checked Compiler flag to "produce debugging symbols [-d]" still I am getting .exe file
(I am using GCC Compiler 5.3.0 on windows7)
You have to install and use the compiler for your TARGET DEVICE. Only then will it produce the right format. You are getting .exe, because you are using a windows compiler. And since Windows runs .exe...

Other possibility is cross-compilation, and you'll have to specify your target platform in compiler arguments.

BlueHazzard

it would help if you tell us for what platform you are developing (arm, avr, pic, nxp...)

christobal

Quote from: anandamu16 on March 03, 2017, 11:42:46 AM
I know there are pre/post build steps, but where to know about the post build steps, I mean what to enter.?
The GCC objcopy documentation should tell you what to do.

For Tricore GCC projects I use:

tricore-objcopy -O ihex  ..\result\$(PROJECT_NAME).elf ..\result\$(PROJECT_NAME).hex


Note: $(PROJECT_NAME) is a Code::Blocks enviroment variable, that expands to the Project name

Quote from: anandamu16 on March 03, 2017, 11:42:46 AM
Did you mean "Project->Build Options->Linker Settings ->Other Linker options"?
Yes. Again, the Linker documentation should tell you what to add.

In my case it is:

-Wl,-Map=..\output\$(PROJECT_NAME).map



anandamu16

QuoteYou have to install and use the compiler for your TARGET DEVICE. Only then will it produce the right format. You are getting .exe, because you are using a windows compiler. And since Windows runs .exe...
Ok thanks. What I understood is.... If I am building my code specific to ARM, I must use "GNU GCC Compiler for ARM" and enable debugging symbols into it. I t will generate an elf file. Am I right?
Quoteit would help if you tell us for what platform you are developing (arm, avr, pic, nxp...)
ARM cortex m0
Any particular lead will be helpful.

Thanks christobl, I will refer GCC document

BlueHazzard

QuoteOk thanks. What I understood is.... If I am building my code specific to ARM, I must use "GNU GCC Compiler for ARM" and enable debugging symbols into it. I t will generate an elf file. Am I right?
Yes, but you have to install it to, codeblocks does not ship with the arm compiler...

christobal

Quote from: anandamu16 on March 03, 2017, 02:33:05 PM
Ok thanks. What I understood is.... If I am building my code specific to ARM, I must use "GNU GCC Compiler for ARM" and enable debugging symbols into it. I t will generate an elf file. Am I right?
In general: Yes, but debugging symbols are not relevant for producing an elf file.

As your target device is a Cortex M0, I assume that you'll not run an OS on your target and therefore need a bare metal GCC Compiler for ARM (aka "gcc-arm-none-eabi"). I did a quick search and found one one here: https://launchpad.net/gcc-arm-embedded/+download

anandamu16

QuoteIn general: Yes, but debugging symbols are not relevant for producing an elf file
Ok thanks, I used to think that to produce elf file, 1 need to enable debug symbols. Thanks for clarification.
QuoteYes, but you have to install it to, codeblocks does not ship with the arm compiler...
I know that.. anyway thanks :)
QuoteI did a quick search and found one one here: https://launchpad.net/gcc-arm-embedded/+download
Thanks for searching, I already had.

I successful build elf file, but still I am not able to get .hex file as output from this elf, I mean I am not getting proper post build commands to do the job. I search on google but no relevent information. If anyone have worked to convert elf file into binary for ARMplz let me know.

christobal

Quote from: anandamu16 on March 06, 2017, 12:41:08 PM
I successful build elf file, but still I am not able to get .hex file as output from this elf, I mean I am not getting proper post build commands to do the job. I search on google but no relevent information. If anyone have worked to convert elf file into binary for ARMplz let me know.

You should use the objcopy tool to convert elf to hex. Try at first from the command line without Code::Blocks post-build step. If you know how to generate the hex file, you can bring it into the post-build steps.
The call should be something like:

objcopy.exe -O ihex ElfFile.elf HexFile.hex

If you get errors, please post the command you're executing and the error message.

anandamu16

Yeah... I am able to build up hex file successfully from .elf file. The corresponding build commands is here arm-eabi-objcopy.exe -O ihex elfFile.elf hexfile.hex

I am thinking, is there any way to create a binary file also? I tried to chenge ihex to ibin and .hex to .bin in above file but it didn't work.
Any idea?

anandamu16

#12
Updating.. yeah I checked.
To get a binary file as output, I need to use 'binary' instead of 'ihex'.
So now I can convert it into binary file also
Post build command is: arm-eabi-objcopy.exe -O binary elfFile.elf binFile.bin
May be anyone working with ARM Compiler can use these build commands directly.
Anyways thanks a lot for your help. :)

anandamu16

Is there any way to also get a .map file as output, Any post build step.?
I checked through binutils of GNU GCC Compiler for ARM document and there was no information on how to get a .map extension file as output

yvesdm3000

Clang based code completion for Code::Blocks:   [url="http://github.com/yvesdm3000/ClangLib"]http://github.com/yvesdm3000/ClangLib[/url]