Build binary file with MinGw32

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
gedeon

Build binary file with MinGw32

Post by gedeon »

I try build binary file with MinGw32 but i have 2 problems

- ld seems doesn't work with the -e xxx option
- and the binary file produced is finaly not a binary file , it's a win 32 file

i use this 2 commande lines :
gcc -c -o ./gdos/kernel/kernel.o ./gdos/kernel/kernel.c
   ld -o ./gdos/bin/kernel.bin -e main --format=binary ./gdos/kernel/kernel.o

i have this result :
ld: warning: cannot find the entry symbol main; defaulting to 00030000

Is someone have a solution ?
Tim

Re:Build binary file with MinGw32

Post by Tim »

gedeon wrote:- ld seems doesn't work with the -e xxx option
Try -e _main.
- and the binary file produced is finaly not a binary file , it's a win 32 file
Try the -b or --format option. Alternatively, link to PE format, then use objcopy to convert to binary.
gedeon

Re:Build binary file with MinGw32

Post by gedeon »

i already tried _main it was the same

and with other format pe-i386 or elf32-386 i have undefined reference to _alloca and __main

i'm tired of this tools that never work

Maybe i could try cygwin but i'm afraid that was the same problem
Tim

Re:Build binary file with MinGw32

Post by Tim »

The _alloca/__main problem is easy.

Calls to _alloca are inserted by gcc on Windows for functions whose local variables are bigger than 4096 bytes; it should generally be possible to avoid this. gcc also inserts a call to __main at the beginning of main; it's OK to write your own version of __main which doesn't do anything.

If you decide you do want _alloca, link against libgcc.a, which should have been provided with gcc.
gedeon

Re:Build binary file with MinGw32

Post by gedeon »

thanks

step by step ....

Now i have a new problem (another one)

i want to use libgcc.a with this command line :

ld -e _main -Ttext 0x030000 -b pe-i386 ./gdos/kernel/kernel.o -L ./gdos/lib -l libgcc.a

and the result is ......

l: cannot find -llibgcc.a

so the path is the good one and the file libgcc.a is present in the directory

so what the matter ?

i also tried with -l ./gdos/lib/gcclib.a but the error message is the same
Tim

Re:Build binary file with MinGw32

Post by Tim »

I had to use a command line like this:
[tt]-lgcc -L/lib/gcc-lib/i686-pc-cygwin/3.2[/tt]

I use gcc 3.2 on Cygwin, so this is the right path for me.
gedeon

Re:Build binary file with MinGw32

Post by gedeon »

To be sure i have reintalled Cygwin on cdrive, it was on e drive

i have no command like lgcc

but when i try tris command in my makefile

ld -e _main -Ttext 0x030000 -b pe-i386 ./gdos/kernel/kernel.o -L\lib\gcc-lib\i686-pc-cygwin\3.3.1

its the same result and i don't understand
the only differnece is the gcc version
Tim

Re:Build binary file with MinGw32

Post by Tim »

OK, maybe I haven't been 100% clear.

Here is the actual command I use to link things.
[tt]ld -o ../../../distrib/tetris.exe \
objects/tetris.o \
../../../lib/crt0.o ../../../lib/framebuf_user.lib ../../../lib/libc.lib ../../../lib/libsys.lib \
-lgcc -L/lib/gcc-lib/i686-pc-cygwin/3.2[/tt]

Modify this as appropriate for your build system.
gedeon

Re:Build binary file with MinGw32

Post by gedeon »

thanks for your help and for your patience, it works !

PS : there is few documentation on -lgcc ( or lc )
Post Reply