Page 1 of 3

GCC and LD problem

Posted: Fri Apr 06, 2007 3:51 pm
by INF1n1t
Ok, guys! It's been a while and I was working on my operating system. I've entered PMode with paging activated (it works! :) . But now I'm stuck on something. When I tried to compile and link my project with gcc and ld...guess what?
memory.h:23:2: invalid preprocessing directive #typedef
memory.h:24:2: invalid preprocessing directive #typedef
memory.h:25:2: invalid preprocessing directive #typedef
...
This is one of the header files. Why #typedef is not working. And this is not the end of the error-list. There are so many more...

Also
imain.o: file not recognized: File format not recognized
imain.o -> I've compiled imain.asm with NASM. But LD doesn't want this...in the documentation of ld, they said that .o is recognized! I'm stuck here! I've read tutorials about GCC-Cross-Compiler, I tried but I got in with many many errors..something like: "Checking for correct version of gmp.h --- no"...I've searched the forum, but nothing! Could you help me, please!

Re: GCC and LD problem

Posted: Fri Apr 06, 2007 5:04 pm
by frank
INF1n1t wrote:Ok, guys! It's been a while and I was working on my operating system. I've entered PMode with paging activated (it works! :) . But now I'm stuck on something. When I tried to compile and link my project with gcc and ld...guess what?
memory.h:23:2: invalid preprocessing directive #typedef
memory.h:24:2: invalid preprocessing directive #typedef
memory.h:25:2: invalid preprocessing directive #typedef
...
This is one of the header files. Why #typedef is not working. And this is not the end of the error-list. There are so many more...

Also
imain.o: file not recognized: File format not recognized
imain.o -> I've compiled imain.asm with NASM. But LD doesn't want this...in the documentation of ld, they said that .o is recognized! I'm stuck here! I've read tutorials about GCC-Cross-Compiler, I tried but I got in with many many errors..something like: "Checking for correct version of gmp.h --- no"...I've searched the forum, but nothing! Could you help me, please!
Ok to start off with, typedef is not a preprocessor directive. Try it without the #. Next what format did you assemble imain.asm too. Did you try elf or coff. Next the error you listed for building a cross compiler is not actually an error. I think that everyone gets that message. Did you try

Code: Select all

make all install
after running configure?

Posted: Sat Apr 07, 2007 3:53 am
by INF1n1t
First of all, I'm stupid: typedef error eliminated. I don't know, what I was thinking yesterday at 1:00 AM. However, GCC gives much errors.

Next, I've fixed the nASM problem by changing from aout to coff and now it works.

And third, yes I run make all but:
"No terminator specified for in-line operator"

And that's why I copied gcc.exe, ld.exe from the cygwin/bin directory to my kernel source directory. Well, now LD works, but GCC does not!

10x frank...

OK, 10x!!!! Problems fixed. The problem was not in the gcc compiler, but in my code. Many errors I've fixed. Hm, I was yesterday on the ASM wave and when I changed to C...I screwed up everything.

Posted: Sat Apr 07, 2007 6:53 am
by supagu
okay i seem to be in sort of the same boat, how ever im stuck on LD with the error message:

"ld: cannot perform PE operations on non PE output file"

ld -T link.ld -o kernel.bin start.o

i read some where this is because start.o was the wrong format, ive tried stuffing around with objcopy, with no luck

Posted: Sat Apr 07, 2007 7:24 am
by Combuster

Posted: Sat Apr 07, 2007 9:16 am
by supagu
the following line from that article:
"make all-gcc install-gcc"

fails with gcc-4.1.2 which says should work

Posted: Sat Apr 07, 2007 9:19 am
by Brynet-Inc
supagu wrote:the following line from that article:
"make all-gcc install-gcc"

fails with gcc-4.1.2 which says should work
Well, It doesn't take a rocket scientist to figure out.. The Wiki has formatting errors.. Or that you could split it up :roll:

Code: Select all

make all-gcc && make install-gcc
or

Code: Select all

make all-gcc
make install-gcc
If it's a build error.. post it here..

Posted: Sat Apr 07, 2007 10:02 am
by frank
One thing, if you are building a cross compiler in cygwin you should try setting the file access mode to binary though the cygwin setup. I had a lot of problems until I changed to binary. Also make sure that you have all of the correct packages installed.

Posted: Sat Apr 07, 2007 10:53 am
by supagu
Brynet-Inc wrote:
supagu wrote:the following line from that article:
"make all-gcc install-gcc"

fails with gcc-4.1.2 which says should work
Well, It doesn't take a rocket scientist to figure out.. The Wiki has formatting errors.. Or that you could split it up :roll:

Code: Select all

make all-gcc && make install-gcc
or

Code: Select all

make all-gcc
make install-gcc
If it's a build error.. post it here..
non of those options work, i've already tried.
if i just type in "make" it says it cant find a makefile

Posted: Sat Apr 07, 2007 10:57 am
by Brynet-Inc
supagu wrote:non of those options work, i've already tried.
if i just type in "make" it says it cant find a makefile
Have you.. ran the configure script? :roll:

Posted: Sat Apr 07, 2007 11:51 am
by INF1n1t
supagu wrote:okay i seem to be in sort of the same boat, how ever im stuck on LD with the error message:

"ld: cannot perform PE operations on non PE output file"

ld -T link.ld -o kernel.bin start.o

i read some where this is because start.o was the wrong format, ive tried stuffing around with objcopy, with no luck
I'm now on the same error. I've searched on the internet and I understood that ld has problems with PE files and that's why we should create a GCC Cross-Compiler, which can create ELF files and so LD will work.

Posted: Sat Apr 07, 2007 11:56 am
by earlz
it's really quite stupid, anyone know of any prebuilt cross-compilers?

Posted: Sat Apr 07, 2007 12:53 pm
by frank
One of the other members of the board posted this sometime ago
http://downloads.sourceforge.net/trion/ ... g_mirror=0

you can try that

Posted: Sat Apr 07, 2007 6:52 pm
by supagu
well i've managed to get bin utils and gcc compiled and installed, how ever i still get the same problem.

ive set the -b and -V arguments for gcc so it uses the cross compiler, also changed the reference to ld to i586-elf-ld as this seems to be the appropriate cross version also.

Now when i run ld i dont get the PE error anymore, how ever it seems i get a bunch of undefined references:


d:\programming\cygwin\home\fabian\bkerndev\Sources>i586-elf-ld -T link.ld -o ker
nel.bin start.o main.o scrn.o gdt.o idt.o isrs.o irq.o timer.o kb.o
i586-elf-ld: warning: cannot find entry symbol start; defaulting to 00100000
start.o:start.asm:(.text+0x2d): undefined reference to `_main'
start.o:start.asm:(.text+0x36): undefined reference to `_gp'
start.o:start.asm:(.text+0x53): undefined reference to `_idtp'
start.o:start.asm:(.text+0x1a3): undefined reference to `_fault_handler'
start.o:start.asm:(.text+0x26f): undefined reference to `_irq_handler'
gdt.o: In function `gdt_install':
gdt.c:(.text+0xf7): undefined reference to `gdt_flush'
idt.o: In function `idt_install':
idt.c:(.text+0x63): undefined reference to `idt_load'
isrs.o: In function `isrs_install':
isrs.c:(.text+0xb): undefined reference to `isr0'
isrs.c:(.text+0x1e): undefined reference to `isr1'
isrs.c:(.text+0x34): undefined reference to `isr2'
isrs.c:(.text+0x47): undefined reference to `isr3'
isrs.c:(.text+0x5d): undefined reference to `isr4'
isrs.c:(.text+0x70): undefined reference to `isr5'
isrs.c:(.text+0x86): undefined reference to `isr6'
isrs.c:(.text+0x99): undefined reference to `isr7'
isrs.c:(.text+0xaf): undefined reference to `isr8'
isrs.c:(.text+0xc2): undefined reference to `isr9'
isrs.c:(.text+0xd8): undefined reference to `isr10'
isrs.c:(.text+0xeb): undefined reference to `isr11'
isrs.c:(.text+0x101): undefined reference to `isr12'
isrs.c:(.text+0x114): undefined reference to `isr13'
isrs.c:(.text+0x12a): undefined reference to `isr14'
isrs.c:(.text+0x13d): undefined reference to `isr15'
isrs.c:(.text+0x153): undefined reference to `isr16'
isrs.c:(.text+0x166): undefined reference to `isr17'
isrs.c:(.text+0x17c): undefined reference to `isr18'
isrs.c:(.text+0x18f): undefined reference to `isr19'
isrs.c:(.text+0x1a5): undefined reference to `isr20'
isrs.c:(.text+0x1b8): undefined reference to `isr21'
isrs.c:(.text+0x1ce): undefined reference to `isr22'
isrs.c:(.text+0x1e1): undefined reference to `isr23'
isrs.c:(.text+0x1f7): undefined reference to `isr24'
isrs.c:(.text+0x20a): undefined reference to `isr25'
isrs.c:(.text+0x220): undefined reference to `isr26'
isrs.c:(.text+0x233): undefined reference to `isr27'
isrs.c:(.text+0x249): undefined reference to `isr28'
isrs.c:(.text+0x25c): undefined reference to `isr29'
isrs.c:(.text+0x272): undefined reference to `isr30'
isrs.c:(.text+0x285): undefined reference to `isr31'
irq.o: In function `irq_install':
irq.c:(.text+0xbb): undefined reference to `irq0'
irq.c:(.text+0xce): undefined reference to `irq1'
irq.c:(.text+0xe4): undefined reference to `irq2'
irq.c:(.text+0xf7): undefined reference to `irq3'
irq.c:(.text+0x10d): undefined reference to `irq4'
irq.c:(.text+0x120): undefined reference to `irq5'
irq.c:(.text+0x136): undefined reference to `irq6'
irq.c:(.text+0x149): undefined reference to `irq7'
irq.c:(.text+0x15f): undefined reference to `irq8'
irq.c:(.text+0x172): undefined reference to `irq9'
irq.c:(.text+0x188): undefined reference to `irq10'
irq.c:(.text+0x19b): undefined reference to `irq11'
irq.c:(.text+0x1b1): undefined reference to `irq12'
irq.c:(.text+0x1c4): undefined reference to `irq13'
irq.c:(.text+0x1da): undefined reference to `irq14'
irq.c:(.text+0x1ed): undefined reference to `irq15'


btw, im using the sample from here:
http://www.osdever.net/bkerndev/index.php

most of these are in an asm file (and prefixed with an underscore)

Posted: Sun Apr 08, 2007 3:33 am
by Candy
That indeed looks like an ancient Fortran hack. Don't use underscores - or use them and tell all tools to do so. IE, -mno-underscores or -fno-leading-underscores or -munderscores or -fleading-underscores for either not using them or using them.