Generating hex file using gcc

18,828

Solution 1

By using objcopy we can make hex file

gcc -c example.c

objcopy --change-address 0xE0000 -O ihex example.o example.hex

it will generate example.hex file

use Bless Hex Editor to see the .hex file clearly

Solution 2

First you need to use the linker ld to create a raw binary binary file. Then use objcopy to create the hex file.

Share:
18,828
Rgarg
Author by

Rgarg

Updated on July 05, 2022

Comments

  • Rgarg
    Rgarg over 1 year

    I have a small C function and I want to make a hex file for it.

    Running

    gcc -c in.c 
    

    makes an object file But I need hex file for this standalone function. I need to put this on a separate location, so that I can simply JMP to this location from my main code. But I want this to be in hex format.

    I cant do a -

    gcc -c in.c -o in.hex 
    

    This is not working.. Please help me out..

  • fkl
    fkl over 10 years
    haven't used objcopy before. +1
  • Seng Cheong
    Seng Cheong over 10 years
    Funny.... He never asked about an address. Yet you and cyberworm both show the exact same example. Almost like you both saw it somewhere.... Hmm.