Page 1 of 2

Cross Compiler use problem

Posted: Mon Apr 26, 2010 7:54 am
by assainator
heey all,

I have followed the tutorial to build a cross compiler from the wiki: http://wiki.osdev.org/GCC_Cross-Compiler
everything compiled nicely and I have the executables.
The thing now is when I try to compile a file I get the error:
gcc: error trying to exec 'cc1': execvp: No such file or directory
I think this means I am missing the 'cc1' executable. And indeed I can't find it in the /usr/cross/i586-elf/bin/ directory
or in the /usr/cross/bin directory.

What did I do wrong?

I compiled the cross compiler with cygwin.


Thanks in advance,
assainator

Re: Cross Compiler use problem

Posted: Mon Apr 26, 2010 8:01 am
by Solar
cc1 is the "real" C compiler (cc1plus being the C++ compiler), to which gcc is merely a front-end. If it wasn't installed somewhere in /usr/cross/, something went wrong during your build process.

Did you add /usr/cross/bin to your PATH, and did you call ${TARGET}-gcc? ("Usage" section of the tutorial.)

Try this line:

Code: Select all

find /usr/cross -name "*cc1*
It should find something in your /usr/cross, or something definitely went wrong.

Re: Cross Compiler use problem

Posted: Mon Apr 26, 2010 8:07 am
by gerryg400
On my cross-compiler, cc1 is in this directory (not a bin directory)

/Users/gerryg/artix/usr/libexec/gcc/x86_64-elf/4.4.2

- gerryg400

Re: Cross Compiler use problem

Posted: Mon Apr 26, 2010 8:24 am
by assainator
after looking trough all the directories i found it in:
/usr/cross/libexec/gcc/i586-elf/4.2.4

the find command didn't gave me anything though

Another thing that I found out, is that I tried to use it from the windows command prompt instead of the cygwin bash chell

Thanks for the help,

assinator

Re: Cross Compiler use problem

Posted: Mon Apr 26, 2010 8:41 am
by Solar
assainator wrote:Another thing that I found out, is that I tried to use it from the windows command prompt instead of the cygwin bash shell
Well? Does it work when you use it from the Cygwin shell?

Re: Cross Compiler use problem

Posted: Mon Apr 26, 2010 8:54 am
by fronty
How did you configure GCC (cc -V)? I've encountered that kind of issues when accidently gave --libexec-dir to configure script twice and compiler driver thought cc1 was at some very funky directory.

Re: Cross Compiler use problem

Posted: Mon Apr 26, 2010 9:06 am
by Solar
He said he followed the tutorial, so I assume he didn't do anything funky with libexecdir... or I'll bite his head off once he admits so. 8)

Re: Cross Compiler use problem

Posted: Mon Apr 26, 2010 10:45 am
by assainator
[-o< YES!!!! I can keep my head!
After trying some stuff:
1. It worked in the cygwin bash shell immediately =
2. When I copied the cc1.exe file to the /usr/cross/bin directory, everything works from the windows command prompt as well
3. the command 'find /usr/cross/ -name "*cc1*' doesn't work on the windows command prompt for some reason :?

Thanks for attending to my problem.

Re: Cross Compiler use problem

Posted: Mon Apr 26, 2010 11:04 am
by Combuster
a different find is built into cmd.exe, of course it doesn't work

Re: Cross Compiler use problem

Posted: Mon Apr 26, 2010 12:40 pm
by assainator
I know, I should have placed a more sarcastic :roll: emoticon after the sentence....

Re: Cross Compiler use problem

Posted: Mon Apr 26, 2010 3:38 pm
by pcmattman
2. When I copied the cc1.exe file to the /usr/cross/bin directory, everything works from the windows command prompt as well
Sign of a mis-configured cross-compiler. Running /usr/cross/bin/i586-elf-gcc should work without requiring cc1 to be moved or linked - it knows where cc1 is. Note that I have seen this error when you run the binaries in /usr/cross/i586-elf/bin instead of those in /usr/cross/bin.

Are you sure you followed the tutorial to the letter?

Re: Cross Compiler use problem

Posted: Mon Apr 26, 2010 11:47 pm
by assainator
The binary's in both directories had this problem.

And yes, I did everything the tutorial told me to do.

I Do have another problem though:
If I link my kernel, for every function in another C file (but that is declared by a included header file) turns into a:
kernel.c:(.text+0x737): undefined reference to `itoa'
before I used the cross compiler, I was using DJGPP. That worked fine.
my linkerscript:

Code: Select all

ENTRY(start)
phys = 0x00100000;
SECTIONS
{
  .text phys : AT(phys) {
    code = .;
    *(.text)
    . = ALIGN(4096);
  }
  .data : AT(phys + (data - code))
  {
    data = .;
    *(.data)
    . = ALIGN(4096);
  }
  .bss : AT(phys + (bss - code))
  {
    bss = .;
    *(.bss)
    . = ALIGN(4096);
  }
  end = .;_end = .;__end = .;___KERNEL_END = .;
}
my commandline:

Code: Select all

i586-elf-ld -T link.ld -o kernel.bin st.o k.o prnt.o s.o gdt.o idt.o isr.o irq.o tmr.o kbd.o pag.o p_a.o mem.o pnc.o cid_a.o cid.o fd.o

Re: Cross Compiler use problem

Posted: Tue Apr 27, 2010 1:23 am
by gravaera
Hi,

Do you use 'itoa()' anywhere in your source? Is there a reason why it's strange that 'itoa()' cannot be found? Do you link to a C stdlib, or use an #include <stdlib.h>? If you do, then please write your own version of the function, or extract it from somewhere and link to it.

If you do not explicitly call 'itoa' in your source, then could you please read up on invoking the compiler to output freestanding code? This question is very indicative of a lazy mind. It is impossible for you not to know that 'undefined reference' errors at the linking phase are due to...undefined references!

An undefined reference is solved by providing the relevant object code to the linker. If you didn't know this, then it's also obvious that you aren't an experienced programmer. Because experienced programmers work on large projects which are modular, and are linked up eventually at some point. Most programmers with enough experience would have by now handled at work, the typical large data processing application which links to some RDBMS library etc. I have no idea how MSVC works. Maybe it hides this kind of thing from programmers, and dumbs them down.

However you take it, a programmer who doesn't know the basics of linking object code together cannot possibly hope to produce any useful kernel code. This is pre-requisite knowledge.

--Do better,
gravaera

Re: Cross Compiler use problem

Posted: Tue Apr 27, 2010 1:32 am
by Solar
Thank you, now please shift one gear down. 8)

But it's true, debugging a unresolved reference should be a piece of cake:
  • Which .o file should itoa() be defined in?
  • Is the symbol reported as missing actually in the expected .o file?
  • Why not?
I just realized we might need a Wiki page detailing basic debugging techniques. I've answered this particular one once too often...

Edit: Wait, we already got Troubleshooting... perhaps we need a sister page "Basic Troubleshooting"...

Re: Cross Compiler use problem

Posted: Tue Apr 27, 2010 1:50 am
by assainator
i'm sorry, it's my fault, I should have posted the complete list......
st.o:(.text+0x2d): undefined reference to `_kmain'
st.o:(.text+0x39): undefined reference to `_gp'
st.o:(.text+0x56): undefined reference to `_idtp'
st.o:(.text+0x1a6): undefined reference to `_fault_handler'
st.o:(.text+0x272): undefined reference to `_irq_handler'
k.o: In function `kmain':
kernel.c:(.text+0x24): undefined reference to `timer_irq_install'
kernel.c:(.text+0x2f): undefined reference to `ClearScreen'
kernel.c:(.text+0x3b): undefined reference to `GotoXY'
kernel.c:(.text+0x48): undefined reference to `SetMargin'
kernel.c:(.text+0xcf): undefined reference to `GotoXY'
kernel.c:(.text+0xf3): undefined reference to `GotoXY'
kernel.c:(.text+0x117): undefined reference to `GotoXY'
kernel.c:(.text+0x1c4): undefined reference to `GotoXY'
kernel.c:(.text+0x20d): undefined reference to `GotoXY'
kernel.c:(.text+0x21c): undefined reference to `strlen'
kernel.c:(.text+0x230): undefined reference to `itoa'
kernel.c:(.text+0x278): undefined reference to `ClearScreen'
kernel.c:(.text+0x282): undefined reference to `alloc'
kernel.c:(.text+0x29c): undefined reference to `itoa'
kernel.c:(.text+0x2ab): undefined reference to `GotoXY'
kernel.c:(.text+0x2dc): undefined reference to `alloc'
kernel.c:(.text+0x333): undefined reference to `itoa'
kernel.c:(.text+0x342): undefined reference to `GotoXY'
k.o: In function `CLI':
kernel.c:(.text+0x3a3): undefined reference to `memset'
kernel.c:(.text+0x3ab): undefined reference to `ClearScreen'
kernel.c:(.text+0x3b7): undefined reference to `GotoXY'
kernel.c:(.text+0x3c4): undefined reference to `SetMargin'
kernel.c:(.text+0x40b): undefined reference to `memset'
kernel.c:(.text+0x413): undefined reference to `GetY'
kernel.c:(.text+0x43f): undefined reference to `strequel'
kernel.c:(.text+0x45a): undefined reference to `strequel'
kernel.c:(.text+0x53e): undefined reference to `strequel'
kernel.c:(.text+0x554): undefined reference to `printf'
kernel.c:(.text+0x570): undefined reference to `strequel'
kernel.c:(.text+0x5b2): undefined reference to `printf'
kernel.c:(.text+0x5ca): undefined reference to `printf'
kernel.c:(.text+0x5e2): undefined reference to `printf'
kernel.c:(.text+0x5fa): undefined reference to `printf'
kernel.c:(.text+0x612): undefined reference to `printf'
k.o:kernel.c:(.text+0x62a): more undefined references to `printf' follow
k.o: In function `CLI':
kernel.c:(.text+0x6e7): undefined reference to `strequel'
kernel.c:(.text+0x725): undefined reference to `GetTotalTicks'
kernel.c:(.text+0x737): undefined reference to `itoa'
kernel.c:(.text+0x775): undefined reference to `strequel'
kernel.c:(.text+0x7a2): undefined reference to `GetTicks'
kernel.c:(.text+0x7be): undefined reference to `printf'
kernel.c:(.text+0x7da): undefined reference to `strequel'
kernel.c:(.text+0x82a): undefined reference to `itoa'
kernel.c:(.text+0x868): undefined reference to `strequel'
kernel.c:(.text+0x874): undefined reference to `ClearScreen'
kernel.c:(.text+0x880): undefined reference to `GotoXY'
kernel.c:(.text+0x890): undefined reference to `printf'
kernel.c:(.text+0x8ac): undefined reference to `strequel'
kernel.c:(.text+0x8e6): undefined reference to `printf'
kernel.c:(.text+0x902): undefined reference to `strequel'
kernel.c:(.text+0x916): undefined reference to `alloc'
kernel.c:(.text+0x92a): undefined reference to `printf'
kernel.c:(.text+0x934): undefined reference to `GetUsedMemory'
kernel.c:(.text+0x942): undefined reference to `printf'
kernel.c:(.text+0x95e): undefined reference to `strequel'
kernel.c:(.text+0x96a): undefined reference to `GetAllocatedPageTables'
kernel.c:(.text+0x97b): undefined reference to `printf'
prnt.o: In function `PrintString':
printing.c:(.text+0x13a): undefined reference to `strlen'
prnt.o: In function `MoveRow':
printing.c:(.text+0x1c7): undefined reference to `memset16'
prnt.o: In function `printf':
printing.c:(.text+0x5bb): undefined reference to `strlen'
gdt.o: In function `gdt_install':
gdt_setup.c:(.text+0xf0): undefined reference to `gdt_flush'
idt.o: In function `idt_install':
idt_setup.c:(.text+0xa2): undefined reference to `memset'
idt_setup.c:(.text+0xaa): undefined reference to `idt_load'
isr.o: In function `isrs_install':
isr_setup.c:(.text+0x7): undefined reference to `isr0'
isr_setup.c:(.text+0x1e): undefined reference to `isr1'
isr_setup.c:(.text+0x35): undefined reference to `isr2'
isr_setup.c:(.text+0x4c): undefined reference to `isr3'
isr_setup.c:(.text+0x63): undefined reference to `isr4'
isr_setup.c:(.text+0x7a): undefined reference to `isr5'
isr_setup.c:(.text+0x91): undefined reference to `isr6'
isr_setup.c:(.text+0xa8): undefined reference to `isr7'
isr_setup.c:(.text+0xbf): undefined reference to `isr8'
isr_setup.c:(.text+0xd6): undefined reference to `isr9'
isr_setup.c:(.text+0xed): undefined reference to `isr10'
isr_setup.c:(.text+0x104): undefined reference to `isr11'
isr_setup.c:(.text+0x11b): undefined reference to `isr12'
isr_setup.c:(.text+0x132): undefined reference to `isr13'
isr_setup.c:(.text+0x149): undefined reference to `isr14'
isr_setup.c:(.text+0x160): undefined reference to `isr15'
isr_setup.c:(.text+0x177): undefined reference to `isr16'
isr_setup.c:(.text+0x18e): undefined reference to `isr17'
isr_setup.c:(.text+0x1a5): undefined reference to `isr18'
isr_setup.c:(.text+0x1bc): undefined reference to `isr19'
isr_setup.c:(.text+0x1d3): undefined reference to `isr20'
isr_setup.c:(.text+0x1ea): undefined reference to `isr21'
isr_setup.c:(.text+0x201): undefined reference to `isr22'
isr_setup.c:(.text+0x218): undefined reference to `isr23'
isr_setup.c:(.text+0x22f): undefined reference to `isr24'
isr_setup.c:(.text+0x246): undefined reference to `isr25'
isr_setup.c:(.text+0x25d): undefined reference to `isr26'
isr_setup.c:(.text+0x274): undefined reference to `isr27'
isr_setup.c:(.text+0x28b): undefined reference to `isr28'
isr_setup.c:(.text+0x2a2): undefined reference to `isr29'
isr_setup.c:(.text+0x2b9): undefined reference to `isr30'
isr_setup.c:(.text+0x2d0): undefined reference to `isr31'
isr.o: In function `fault_handler':
isr_setup.c:(.text+0x301): undefined reference to `GotoXY'
irq.o: In function `irq_remap':
irq_setup.c:(.text+0x33): undefined reference to `outb'
irq_setup.c:(.text+0x45): undefined reference to `outb'
irq_setup.c:(.text+0x54): undefined reference to `outb'
irq_setup.c:(.text+0x66): undefined reference to `outb'
irq_setup.c:(.text+0x75): undefined reference to `outb'
irq.o:irq_setup.c:(.text+0x87): more undefined references to `outb' foll
irq.o: In function `irq_install':
irq_setup.c:(.text+0xde): undefined reference to `irq0'
irq_setup.c:(.text+0xf5): undefined reference to `irq1'
irq_setup.c:(.text+0x10c): undefined reference to `irq2'
irq_setup.c:(.text+0x123): undefined reference to `irq3'
irq_setup.c:(.text+0x13a): undefined reference to `irq4'
irq_setup.c:(.text+0x151): undefined reference to `irq5'
irq_setup.c:(.text+0x168): undefined reference to `irq6'
irq_setup.c:(.text+0x17f): undefined reference to `irq7'
irq_setup.c:(.text+0x196): undefined reference to `irq8'
irq_setup.c:(.text+0x1ad): undefined reference to `irq9'
irq_setup.c:(.text+0x1c4): undefined reference to `irq10'
irq_setup.c:(.text+0x1db): undefined reference to `irq11'
irq_setup.c:(.text+0x1f2): undefined reference to `irq12'
irq_setup.c:(.text+0x209): undefined reference to `irq13'
irq_setup.c:(.text+0x220): undefined reference to `irq14'
irq_setup.c:(.text+0x237): undefined reference to `irq15'
irq.o: In function `irq_handler':
irq_setup.c:(.text+0x292): undefined reference to `outb'
irq_setup.c:(.text+0x2a1): undefined reference to `outb'
tmr.o: In function `setuptime':
timer.c:(.text+0x2c): undefined reference to `outb'
timer.c:(.text+0x52): undefined reference to `outb'
timer.c:(.text+0x7f): undefined reference to `outb'
tmr.o:timer.c:(.text+0xaf): more undefined references to `outb' follow
tmr.o: In function `timer_irq_handler':
timer.c:(.text+0x1f1): undefined reference to `GetX'
timer.c:(.text+0x1f9): undefined reference to `GetY'
timer.c:(.text+0x218): undefined reference to `GotoXY'
timer.c:(.text+0x239): undefined reference to `printf'
timer.c:(.text+0x24c): undefined reference to `GotoXY'
timer.c:(.text+0x25b): undefined reference to `outb'
tmr.o: In function `timer_phase':
timer.c:(.text+0x2e4): undefined reference to `outb'
timer.c:(.text+0x2fa): undefined reference to `outb'
timer.c:(.text+0x313): undefined reference to `outb'
kbd.o: In function `getstringw':
KeyBoard.c:(.text+0xf0): undefined reference to `GotoXY'
KeyBoard.c:(.text+0x110): undefined reference to `GotoXY'
KeyBoard.c:(.text+0x133): undefined reference to `GotoXY'
kbd.o: In function `getstring':
KeyBoard.c:(.text+0x1e1): undefined reference to `itoa'
KeyBoard.c:(.text+0x1f0): undefined reference to `GotoXY'
KeyBoard.c:(.text+0x20e): undefined reference to `GotoXY'
KeyBoard.c:(.text+0x231): undefined reference to `GotoXY'
KeyBoard.c:(.text+0x253): undefined reference to `GotoXY'
kbd.o: In function `keyboard_handler':
KeyBoard.c:(.text+0x35f): undefined reference to `outb'
pag.o: In function `paging_install':
Paging.c:(.text+0x8): undefined reference to `__KERNEL_END'
Paging.c:(.text+0xbc): undefined reference to `enablePaging'
mem.o: In function `alloc':
Memory.c:(.text+0x7b): undefined reference to `itoa'
Memory.c:(.text+0x8a): undefined reference to `GotoXY'
Memory.c:(.text+0x200): undefined reference to `itoa'
Memory.c:(.text+0x21a): undefined reference to `itoa'
mem.o: In function `GetWaistedMemory':
Memory.c:(.text+0x2ea): undefined reference to `itoa'
Memory.c:(.text+0x2f2): undefined reference to `GetX'
Memory.c:(.text+0x2fa): undefined reference to `GetY'
Memory.c:(.text+0x309): undefined reference to `GotoXY'
Memory.c:(.text+0x339): undefined reference to `GotoXY'
Memory.c:(.text+0x3da): undefined reference to `itoa'
Memory.c:(.text+0x3f6): undefined reference to `itoa'
Memory.c:(.text+0x40d): undefined reference to `itoa'
Memory.c:(.text+0x415): undefined reference to `GetX'
Memory.c:(.text+0x41d): undefined reference to `GetY'
Memory.c:(.text+0x42c): undefined reference to `GotoXY'
Memory.c:(.text+0x45a): undefined reference to `GotoXY'
Memory.c:(.text+0x488): undefined reference to `GotoXY'
Memory.c:(.text+0x4b8): undefined reference to `GotoXY'
pnc.o: In function `panic':
Panic.c:(.text+0x7): undefined reference to `ClearScreen'
cid_a.o: In function `_CheckCPUID':
cpuid.asm:(.text+0x18): undefined reference to `__CPUSupports_CPUID'
cid_a.o: In function `__GetCPUVendorString':
cpuid.asm:(.text+0x27): undefined reference to `__CPU_VENDOR_STRING_ID'
cpuid.asm:(.text+0x2d): undefined reference to `__CPU_VENDOR_STRING_ID'
cpuid.asm:(.text+0x33): undefined reference to `__CPU_VENDOR_STRING_ID'
cid.o: In function `GetCPUVendorString':
cpuid.c:(.text+0x7): undefined reference to `CheckCPUID'
cpuid.c:(.text+0x15): undefined reference to `_GetCPUVendorString'
fd.o: In function `GetFloppyConfiguration':
FloppyIO.c:(.text+0xe): undefined reference to `outb'
FloppyIO.c:(.text+0x34): undefined reference to `outb'
FloppyIO.c:(.text+0x61): undefined reference to `outb'
fd.o: In function `GetFloppyConfigurationSimple':
FloppyIO.c:(.text+0xa5): undefined reference to `outb'
FloppyIO.c:(.text+0xcb): undefined reference to `outb'
fd.o:FloppyIO.c:(.text+0xf8): more undefined references to `outb' follow
I other words: these are almost all the functions in my kernel.
And as I said, it worked with DJGPP

and i'm not that stupid to not try and include the specific .o file.
That was the first thing I looked at, but no.