Page 1 of 1
HELP! With cygwin
Posted: Fri Jun 22, 2007 1:01 pm
by t0xic
Hey everyone,
I been using djgpp to link/build my kernel, but I recently decided to switch over to cygwin. I get to it compile but it wants to link with a __main and _alloca. I know there is a switch to turn this off, but for the life of me I can't remember it. Also, linking with the cygwin ld tells me I can't link a.out files, and my kernel is now 20kb bigger, and I haven't added any code. <what a run on sentence>. I would appreciate any help
thanks
-t0xic
Posted: Fri Jun 22, 2007 2:38 pm
by Combuster
Sounds like a FAQ question to me:
OSDev Wiki wrote:Creating a dedicated (cross-) compiler for your OS development work can save you many headaches. If...
* ...your system compiler drags in references to alloca() or other OS-dependent things,
(
GCC Cross-Compiler )
as for the switch, my first guess would be reading the manpages
Posted: Fri Jun 22, 2007 7:30 pm
by frank
The switches I use are
Code: Select all
-fno-builtin -nostdlib -ffreestanding
for my c files and
Code: Select all
-fno-builtin -nostdlib -fno-exceptions -fno-rtti
for my c++ files.
EDIT: You will really want to build a cross compiler, so that should be the first thing that you do. Unless you like PE files.
Posted: Sat Jun 23, 2007 4:29 am
by AJ
Hi,
I got djgpp working fine with the switches frank has mentioned, although I have now switched to Cygwin and a cross compiler. I would definitely recommend the latter.
Cheers,
Adam
Posted: Sat Jun 23, 2007 8:34 am
by t0xic
I use those switches too. Two questions...
- Why can't I use --no-leading-underscores?
- What did you guys use as your target machine for yuor cross compiler. When ever I try i386-pc-none or i486-linux, the makefile freaks out. If I am not trying to use elf, what exe format should I use, and how do I put it in the switch? ?i386-coff?
Any help would be appreciated.
Thanks
--t0xic
Posted: Sat Jun 23, 2007 8:45 am
by Brynet-Inc
Well, For one isn't it -fno-leading-underscores ?
BTW The target for ELF is clearly defined in the Wiki article
GCC Cross-Compiler.
Most people use the target i486-elf or i586-elf.. But I'm guessing i386/i686 are valid as well.
Posted: Sat Jun 23, 2007 8:54 am
by t0xic
I meant I don't want to use elf. I'm not really sure which format I'm using lol. I've been using coff I think, as thats the default format for djgpp. I had tried -fno-leading-underscores but my cygwin is obviously screwed up.
--t0xic
Posted: Sat Jun 23, 2007 9:20 am
by frank
Well I do believe that cygwin defaults to no leading underscores. As for the target
i686-pc-elf or
i586-pc-elf is usually the one people use. Objdump says it supports
elf32-i386 coff-i386 elf32-little elf32-big srec symbolsrec tekhex binary ihex
However I think that
i586-pc-msdosdjgpp is also a valid target. I can't tell you what it supports though.
Posted: Sat Jun 23, 2007 9:48 am
by jnc100
t0xic wrote:I meant I don't want to use elf. I'm not really sure which format I'm using lol.
I think djgpp uses coff (Microsoft style) as the object file for output from gcc/gas, and pe as the executable format that ld produces. Typically, to specify an executable format, you pass the --oformat TARGET option to ld, where TARGET is one of the targets produced by the output to ld --help.
In particular, my Cygwin ld produces:
Code: Select all
ld: supported targets: pe-i386 pei-i386 elf32-i386 elf32-little elf32-big srec symbolsrec tekhex binary ihex
ld: supported emulations: i386pe
although you actually can't use some of them like the elf ones from Cygwin (it expects PE output, as evidenced by the supported emulations list).
On the other hand, a cross compiled binutils will give:
Code: Select all
i586-elf-ld: supported targets: elf32-i386 coff-i386 elf32-little elf32-big srec symbolsrec tekhex binary ihex
i586-elf-ld: supported emulations: elf_i386
which can produce elf executables.
The 'target' which people are discussing here, like 'i586-elf' etc is actually a machine name for the target that you want your code to run on, and is passed to gcc through use of the '-b <machine>' options. All this does is run the particular version of gcc that you have requested, e.g. running 'gcc -b i586-elf' will actually just pass all your options on to i586-elf-gcc. Now each particular version of gcc you have installed will have default values for certain options, e.g. the default executable version for i586-elf is elf. Its default architecture is to generate x86 code for an i586 or above, and it doesn't add any os specific code (like i586-linux-elf would).
I would suggest you cross compile a new version of gcc and binutils under cygwin, by following the instructions in
GCC_Cross-Compiler.
Regards,
John.
Posted: Sun Jun 24, 2007 7:18 am
by t0xic
Thanks everyone;
Ok, I got i586-elf to work, and I'm in the process of compiling the binutils, but when I try to make ld, make tells me that it has already configures ./ld, even though I delete the folder. IS this a common bug or am I doing something wrong?
Thanks
--t0xic
Posted: Sun Jun 24, 2007 8:29 am
by frank
Well does it complete the build process and that is just some useless little info message or does it appear to fail after telling you that?
Posted: Sun Jun 24, 2007 8:41 am
by t0xic
@frank
Make stops what it's doing and gives me the fail on error message
--t0xic
Posted: Sun Jun 24, 2007 10:03 am
by frank
First off are you following the wiki instructions and are building in a separate directory? If you are try deleting everything in build-binutils and running configure and make again.
Also when you first installed cygwin did you pick the Unix/binary option for file mode? If you picked text mode then that could be a problem.
Finally do you have a the necessary packages for building binutils. I can't remember all of them but I know you need flex and bison.
Posted: Sun Jun 24, 2007 12:27 pm
by t0xic
I believe I found the problem. I was reading the error too literally (or maybe not enough). Make told me to run make distclean in the source directory, not the build-binutils/ld directory. Make is running fine now, hopefully no more errors =)
Thanks
--t0xic