Cross-compilers

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
Isaac
Member
Member
Posts: 66
Joined: Sat Dec 07, 2013 7:08 pm

Cross-compilers

Post 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?
User avatar
Minoto
Member
Member
Posts: 89
Joined: Thu May 12, 2011 7:24 pm

Re: Cross-compilers

Post by Minoto »

Are you also following the Bare_Bones tutorial? It explains how to use the cross compiler once you've built it.
Those who understand Unix are doomed to copy it, poorly.
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Re: Cross-compilers

Post by Combuster »

Where's the

Code: Select all

-c
? #-o
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
Isaac
Member
Member
Posts: 66
Joined: Sat Dec 07, 2013 7:08 pm

Re: Cross-compilers

Post 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?
User avatar
Minoto
Member
Member
Posts: 89
Joined: Thu May 12, 2011 7:24 pm

Re: Cross-compilers

Post 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?
Those who understand Unix are doomed to copy it, poorly.
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Re: Cross-compilers

Post 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.
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
Isaac
Member
Member
Posts: 66
Joined: Sat Dec 07, 2013 7:08 pm

Re: Cross-compilers

Post 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!!
User avatar
sortie
Member
Member
Posts: 931
Joined: Wed Mar 21, 2012 3:01 pm
Libera.chat IRC: sortie

Re: Cross-compilers

Post 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.
User avatar
sortie
Member
Member
Posts: 931
Joined: Wed Mar 21, 2012 3:01 pm
Libera.chat IRC: sortie

Re: Cross-compilers

Post 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.
Last edited by sortie on Thu Dec 12, 2013 2:00 pm, edited 1 time in total.
User avatar
BMW
Member
Member
Posts: 286
Joined: Mon Nov 05, 2012 8:31 pm
Location: New Zealand

Re: Cross-compilers

Post 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++
Currently developing Lithium OS (LiOS).

Recursive paging saves lives.
"I want to change the world, but they won't give me the source code."
Post Reply