Page 1 of 1
Cross-compilers
Posted: Sun Dec 08, 2013 7:27 pm
by Isaac
Hi,
I followed this page:
http://wiki.osdev.org/GCC_Cross-Compiler
and built a cross-compiler for x86_64-elf. But when I enter the command "gcc Kernel.c-o kernel.o", I get this error message:
Code: Select all
/home/isaac/Cross-compiler/lib/gcc/x86_64-elf/4.8.2/../../../../x86_64-elf/bin/ld: cannot find crt0.o: No such file or directory
/home/isaac/Cross-compiler/lib/gcc/x86_64-elf/4.8.2/../../../../x86_64-elf/bin/ld: cannot find -lc
collect2: error: ld returned 1 exit status
What should I do about this error? How can I get it to work?
Re: Cross-compilers
Posted: Sun Dec 08, 2013 9:22 pm
by Minoto
Are you also following the
Bare_Bones tutorial? It explains how to use the cross compiler once you've built it.
Re: Cross-compilers
Posted: Sun Dec 08, 2013 11:57 pm
by Combuster
Where's the
?
Re: Cross-compilers
Posted: Tue Dec 10, 2013 7:33 pm
by Isaac
I entered the command from the bare bones tutorial. But I just get this error:
Code: Select all
/home/isaac/Kernel.c: In function ‘print’:
/home/isaac/Kernel.c:11:12: warning: value computed is not used [-Wunused-value]
i++;} *message++;}}
^
Well, I did modify the command a little... instead of writing this:
Code: Select all
i586-elf-gcc -c kernel.c -o kernel.o -std=gnu99 -ffreestanding -O2 -Wall -Wextra
I wrote this:
Code: Select all
x86_64-elf-gcc -c kernel.c -o kernel.o -std=gnu99 -ffreestanding -O2 -Wall -Wextra
but I just did that because my compiler is for x86_64-elf not for i586-elf. And to Combuster that asked me to at least put in a -c into my command... I tried that and it does work. But my OS won't boot using grub. Grub just prints the following error:
Code: Select all
Error 13: Invalid or unsupported executable format
Now, here is the source code of kernel.c:
Code: Select all
void print(char *message, int line,int ch){
char *vm=(char *)0xb8000;
int i=(line*80*2);
i=i+(ch*2);
while(*message!=0){
if (*message=='\n'){line++;
i=(line*80*2);}
else {vm[i]=*message;
i++;
vm[i]=0x07;
i++;} *message++;}}
void kernel_main(){
print("Welcome!\nHow do you like my OS?",0,0);}
Not bad. Right? So what can be the problem?
Re: Cross-compilers
Posted: Tue Dec 10, 2013 8:15 pm
by Minoto
Isaac wrote:I entered the command from the bare bones tutorial. But I just get this error:
Code: Select all
/home/isaac/Kernel.c: In function ‘print’:
/home/isaac/Kernel.c:11:12: warning: value computed is not used [-Wunused-value]
i++;} *message++;}}
^
Okay...so, think about the expression that the compiler is helpfully pointing at, and fix it.
Isaac wrote:I wrote this:
Code: Select all
x86_64-elf-gcc -c kernel.c -o kernel.o -std=gnu99 -ffreestanding -O2 -Wall -Wextra
but I just did that because my compiler is for x86_64-elf not for i586-elf. And to Combuster that asked me to at least put in a -c into my command... I tried that and it does work. But my OS won't boot using grub. Grub just prints the following error:
Code: Select all
Error 13: Invalid or unsupported executable format
Where's your multiboot header? Are you including the short assembly bootstrap as shown in the tutorial?
Re: Cross-compilers
Posted: Wed Dec 11, 2013 1:06 am
by Combuster
Isaac wrote:And to Combuster that asked me to at least put in a -c into my command...
That's not what it said. You concluded a solution without understanding why.
But I just get this error:
(...)
warning:
Do you know the difference between warning and error? (What is it?)
Not bad. Right?
That's -20% on your grade for illegible code. Didn't bother to calculate the rest of the score.
---
There's just so much wrong with every part of your explanation that I don't believe you meet the required knowledge, nor that you have properly executed the relevant tutorials on the matter at least once.
Re: Cross-compilers
Posted: Wed Dec 11, 2013 4:49 pm
by Isaac
If you would like to see my assembly file, here it is:
Code: Select all
.globl start
start:
jmp main
mboot:
.set ALIGN, 1<<0
.set MEMINFO, 1<<1
.set FLAGS, ALIGN | MEMINFO
.set MAGIC, 0x1BADB002
.set CHECKSUM, -(MAGIC + FLAGS)
.section .multibootHeader
.align 0x4
.long MAGIC
.long FLAGS
.long CHECKSUM
.text
main:
call kernel_main
cli
hlt
As you can see I did include a multiboot header for grub.
Minoto wrote:Okay...so, think about the expression that the compiler is helpfully pointing at, and fix it.
I don't understand the warning.
Combuster wrote:That's -20% on your grade for illegible code. Didn't bother to calculate the rest of the score.
Don't tell me my code is illegible just because
YOU can't read it!!
Re: Cross-compilers
Posted: Wed Dec 11, 2013 5:00 pm
by sortie
You do, of course, realize that you cannot complete the Bare Bones with a x86_64-elf cross-compiler and you must use a ix86-elf cross-compiler? Probably not.
GRUB cannot boot x86_64 multiboot kernels directly, so you should just do a 32-bit kernel instead if you are starting out.
Re: Cross-compilers
Posted: Wed Dec 11, 2013 5:02 pm
by sortie
Isaac wrote:Combuster wrote:That's -20% on your grade for illegible code. Didn't bother to calculate the rest of the score.
Don't tell me my code is illegible just because
YOU can't read it!!
Uh, no. Your coding style is as bad as it gets. I can parse and reformat your C code, which allows me to read it, but I sure as hell can't maintain coding like that.
Re: Cross-compilers
Posted: Wed Dec 11, 2013 5:14 pm
by BMW
Isaac wrote:Code: Select all
void print(char *message, int line,int ch){
char *vm=(char *)0xb8000;
int i=(line*80*2);
i=i+(ch*2);
while(*message!=0){
if (*message=='\n'){line++;
i=(line*80*2);}
else {vm[i]=*message;
i++;
vm[i]=0x07;
i++;} *message++;}}
void kernel_main(){
print("Welcome!\nHow do you like my OS?",0,0);}
A formatting suggestion:
Code: Select all
void print(char *message, int line, int ch)
{
char *vm = (char *)0xB8000;
int i = line * 80 * 2 + ch * 2;
while(*message != 0)
{
if (*message == '\n')
{
i = ++line * 80 * 2;
}
else
{
vm[i++] = *message;
vm[i++] = 0x07;
}
*message++;
}
}
void kernel_main(void)
{
print("Welcome!\nHow do you like my OS?", 0, 0);
}
By the way I think you want message++ at the last line of the loop rather than *message++