Page 1 of 1

the dam djgpp ___main

Posted: Wed Apr 17, 2002 11:00 pm
by blito
Hello :-)
when i compile a .c file, the asm code generated
call a ___main function.
it seems that djgpp call a ___main function into my
main function to initialize something.
anibody knows how to erase it.
what switches do i have to use?
i'm doing my bootloader and when i link the file with
ld i get unresolved references to ___main
WHAT ___MAIN!!!!!!!!!!.
dam!!!!!.
could you help me?, please!!!.
My code:

int main(void) {
return(0)
}

i compile this way
gcc -Wall -S -o nothing.s nothing.c to view the assembler code
gcc -Wall -c -o nothing.o nothing.c to link with ld

i link this way
ld nothing.o

i have tried with gcc -fno-stdlibs but nothing changes

RE:the dam djgpp ___main

Posted: Wed Apr 17, 2002 11:00 pm
by J. Weeks
>On 2002-04-18 07:54:31, blito wrote:
>Hello :-)
>when i compile a .c file, the asm code generated
>call a ___main function.
>it seems that djgpp call a ___main function into my
>main function to initialize something.
>anibody knows how to erase it.
>what switches do i have to use?
>i'm doing my bootloader and when i link the file with
>ld i get unresolved references to ___main
>WHAT ___MAIN!!!!!!!!!!.
>dam!!!!!.
>could you help me?, please!!!.
>My code:
>
>int main(void) {
> return(0)
>}
>
>i compile this way
>gcc -Wall -S -o nothing.s nothing.c to view the assembler code
>gcc -Wall -c -o nothing.o nothing.c to link with ld
>
>i link this way
>ld nothing.o
>
>i have tried with gcc -fno-stdlibs but nothing changes

The problem is with ld, not gcc. You wanna make
sure you're outputting to a bin format... if I
recall:

ld -oformat binary etc.o

Jeff

RE:the dam djgpp ___main

Posted: Thu Apr 18, 2002 11:00 pm
by Chris Giese
>On 2002-04-18 07:54:31, blito wrote:
>Hello :-)
>when i compile a .c file, the asm code generated
>call a ___main function.

All symbols created by the DJGPP compiler
(GCC for DOS) start with 1 underscore, unless
you say "gcc -fno-leading-underscore ..."

The CygWin and MinGW32 compilers (GCC for Win32)
put a call to ___main (3 underscores) into the
code. I don't know why. Just do this:

#ifdef __WIN32__
/* 2 underscores */
int __main(void) { return 0; }
#endif

RE:the dam djgpp ___main

Posted: Thu Apr 18, 2002 11:00 pm
by blito
>On 2002-04-18 13:14:50, J. Weeks wrote:
>>On 2002-04-18 07:54:31, blito wrote:
>>Hello :-)
>>when i compile a .c file, the asm code generated
>>call a ___main function.
>>it seems that djgpp call a ___main function into my
>>main function to initialize something.
>>anibody knows how to erase it.
>>what switches do i have to use?
>>i'm doing my bootloader and when i link the file with
>>ld i get unresolved references to ___main
>>WHAT ___MAIN!!!!!!!!!!.
>>dam!!!!!.
>>could you help me?, please!!!.
>>My code:
>>
>>int main(void) {
>> return(0)
>>}
>>
>>i compile this way
>>gcc -Wall -S -o nothing.s nothing.c to view the assembler code
>>gcc -Wall -c -o nothing.o nothing.c to link with ld
>>
>>i link this way
>>ld nothing.o
>>
>>i have tried with gcc -fno-stdlibs but nothing changes
>
>The problem is with ld, not gcc. You wanna make
>sure you're outputting to a bin format... if I
>recall:
>
>ld -oformat binary etc.o
>
>Jeff

i have done this but nothing changes.
any other idea?
thank's anyway

RE:the dam djgpp ___main

Posted: Thu Apr 18, 2002 11:00 pm
by Guest
>On 2002-04-19 00:20:50, Chris Giese wrote:
>>On 2002-04-18 07:54:31, blito wrote:
>>Hello :-)
>>when i compile a .c file, the asm code generated
>>call a ___main function.
>
>All symbols created by the DJGPP compiler
>(GCC for DOS) start with 1 underscore, unless
>you say "gcc -fno-leading-underscore ..."
>
>The CygWin and MinGW32 compilers (GCC for Win32)
>put a call to ___main (3 underscores) into the
>code. I don't know why. Just do this:
>
>#ifdef __WIN32__
>/* 2 underscores */
>int __main(void) { return 0; }
>#endif
>
the same happens in djgpp (3 underscore).
how can i dissable it!!!.
i'm trying to write a boot loader but i can't because
dgjpp insert unwanted code!!!.
do you know where to go to find information abaut
it.
thank's

RE:the dam djgpp ___main

Posted: Mon Apr 29, 2002 11:00 pm
by Tim Robinson
>On 2002-04-19 10:00:01, Anonymous wrote:
>>On 2002-04-19 00:20:50, Chris Giese wrote:
>>>On 2002-04-18 07:54:31, blito wrote:
[...]
>>The CygWin and MinGW32 compilers (GCC for Win32)
>>put a call to ___main (3 underscores) into the
>>code. I don't know why. Just do this:
>>
>>#ifdef __WIN32__
>>/* 2 underscores */
>>int __main(void) { return 0; }
>>#endif
>>
>the same happens in djgpp (3 underscore).
>how can i dissable it!!!.
>i'm trying to write a boot loader but i can't because
>dgjpp insert unwanted code!!!.
>do you know where to go to find information abaut
>it.

First off, you can't write a boot loader using anything
other than assembly, for a variety of good reasons.

Anyway, nobody's really sure why gcc emits a call to __main();
it's there in all versions and it's apparently impossible to
disable. Just write an empty __main() function and ignore it.