DJGPP Question???

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
Freakyprogrammer

DJGPP Question???

Post by Freakyprogrammer »

ok, I have just started using DJGPP and have just got it working and I compiled a simple "Helo world Program" (about 1kb of text) and it compiled it into an executable a.exe and it works fine but its about 555kb in size... this is simply too large for my OS I cant figure out how to get around or correct this problem, please any feedback would be greatly appriciated, thanks.

         peace out...
             - Freakyprogrammer
Gandalf

RE:DJGPP Question???

Post by Gandalf »

hi friend,

Do you want to run a .exe file in your OS ? I think you just want a plain binary  file that can be loaded as such and executed (correct me if I am wrong).

So if it is just a plain binary that you want then you should be doing the following:

1. Compile ur C file(s) using

gcc -nostdinc -fno-builtin -ffreestanding -c your_c_file_1.c  your_c_file_2.c
2. Now u will have your_c_file_1.o and your_c_file_2.o (The object files)

3. Link the object files using a linker like ld by

ld -nostdlib -T  krnl.ld your_c_file_1.o your_c_file_2.o -o prog.bin

Here prog.bin is the final output binary file that you can wanted.

The krnl.ld is a linker script: Here's a sample.

/* LINKER SCRIPT BEGINS */
ENTRY(entry)
OUTPUT_FORMAT("binary")
SECTIONS
{
    .text 0x100000 :
    {
     *(.text)

     *(.rodata*)
     . = ALIGN(4096);
    }
  
    .data :
    {
     *(.data)
     . = ALIGN(4096);
    }

    .bss :
    {
     *(.bss)

     *(COMMON)
     . = ALIGN(4096);
    }
}
/*LINKER SCRIPT ENDS HERE */

The entry in the ENTRY is the starting point of execution in your program and for a normal C prog it is generally "main".
The .text, .data, .bss are all sections. And here we have tried to start our text section from 0x100000(1Mb). For ur purpose it will work with 0x0.

Hope it helps.

rgds
Gandalf
Post Reply