Compiling C for gross binary

1

How to compile a code in C down-level? (.bin, example).

I am using the IDE Code :: Blocks, and the compiler minGW (I am in Windows, but if you know for Linux the commands are almost identical).

    
asked by anonymous 16.10.2015 / 16:56

2 answers

5

If I understand, you want to generate a raw binary file, without an operating system-dependent format. If so, it's a very basic question for something that is just the tip of the iceberg , it's not simple to mess with it, but okay, you can respond.

Do you already know that you can not use any function that depends on system calls? Not even indirectly. You will have to deal with some things not at hand, since the compiler assumes certain conditions. It almost pays to do it in assembly .

To compile does not change anything. To link changes. You can do this too:

cc -c main.c
objcopy -O binary main.o main.bin

Look like this:

objdump -d main.o
hexdump -C main.bin

It has to be the same.

You probably want to study this . Especially this .

    
16.10.2015 / 17:17
-1

Use the gcc option: link

  

-S
     Stop after the stage of compilation proper; do not assemble. The output is in the form of an assembler code file for each non-assembler input file specified.

     

By default, the assembler file name for a source file is made by replacing the suffix '.c', '.i', etc., with '.s'.

     

Input files that do not require compilation are ignored.

    
16.10.2015 / 17:17