LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 04-22-2010, 12:21 PM   #1
MTK358
LQ 5k Club
 
Registered: Sep 2009
Posts: 6,443
Blog Entries: 3

Rep: Reputation: 723Reputation: 723Reputation: 723Reputation: 723Reputation: 723Reputation: 723Reputation: 723
Can't compile OS example


I am following this tutorial:

http://wiki.osdev.org/Bare_bones#Booting_the_kernel

But I just can't get it to compile. What do you think is wrong?

Code:
$ nasm -f elf -o loader.o loader.s
[michael:test]$ gcc -o kernel.o -c kernel.c -Wall -Wextra -nostdlib -nostartfiles -nodefaultlibs -m32
kernel.c: In function ‘kernel_main’:
kernel.c:1: warning: unused parameter ‘mbd’
[michael:test]$ ld -T linker.ld -o kernel.bin loader.o kernel.o -A i386
ld: i386 architecture of input file `loader.o' is incompatible with i386:x86-64 output
ld: i386 architecture of input file `kernel.o' is incompatible with i386:x86-64 output
I'm often really starting to wish my desktop had 32-bit Linux on it!
 
Old 04-22-2010, 12:23 PM   #2
Sergei Steshenko
Senior Member
 
Registered: May 2005
Posts: 4,481

Rep: Reputation: 454Reputation: 454Reputation: 454Reputation: 454Reputation: 454
Quote:
Originally Posted by MTK358 View Post
I am following this tutorial:

http://wiki.osdev.org/Bare_bones#Booting_the_kernel

But I just can't get it to compile. What do you think is wrong?

Code:
$ nasm -f elf -o loader.o loader.s
[michael:test]$ gcc -o kernel.o -c kernel.c -Wall -Wextra -nostdlib -nostartfiles -nodefaultlibs -m32
kernel.c: In function ‘kernel_main’:
kernel.c:1: warning: unused parameter ‘mbd’
[michael:test]$ ld -T linker.ld -o kernel.bin loader.o kernel.o -A i386
ld: i386 architecture of input file `loader.o' is incompatible with i386:x86-64 output
ld: i386 architecture of input file `kernel.o' is incompatible with i386:x86-64 output
I'm often really starting to wish my desktop had 32-bit Linux on it!
Have you read NASM documentation, the part describing output format ?
 
Old 04-22-2010, 12:32 PM   #3
MTK358
LQ 5k Club
 
Registered: Sep 2009
Posts: 6,443

Original Poster
Blog Entries: 3

Rep: Reputation: 723Reputation: 723Reputation: 723Reputation: 723Reputation: 723Reputation: 723Reputation: 723
Code:
$ nasm -hf

...

valid output formats for -f are (`*' denotes default):
  * bin       flat-form binary files (e.g. DOS .COM, .SYS)
    ith       Intel hex
    srec      Motorola S-records
    aout      Linux a.out object files
    aoutb     NetBSD/FreeBSD a.out object files
    coff      COFF (i386) object files (e.g. DJGPP for DOS)
    elf32     ELF32 (i386) object files (e.g. Linux)
    elf       ELF (short name for ELF32) 
    elf64     ELF64 (x86_64) object files (e.g. Linux)
    as86      Linux as86 (bin86 version 0.3) object files
    obj       MS-DOS 16-bit/32-bit OMF object files
    win32     Microsoft Win32 (i386) object files
    win64     Microsoft Win64 (x86-64) object files
    rdf       Relocatable Dynamic Object File Format v2.0
    ieee      IEEE-695 (LADsoft variant) object file format
    macho32   NeXTstep/OpenStep/Rhapsody/Darwin/MacOS X (i386) object files
    macho     MACHO (short name for MACHO32)
    macho64   NeXTstep/OpenStep/Rhapsody/Darwin/MacOS X (x86_64) object files
    dbg       Trace of all info passed to output stage
Isn't "-f elf" correct, then?
 
Old 04-22-2010, 12:38 PM   #4
Sergei Steshenko
Senior Member
 
Registered: May 2005
Posts: 4,481

Rep: Reputation: 454Reputation: 454Reputation: 454Reputation: 454Reputation: 454
Quote:
Originally Posted by MTK358 View Post
Code:
$ nasm -hf

...

valid output formats for -f are (`*' denotes default):
  * bin       flat-form binary files (e.g. DOS .COM, .SYS)
    ith       Intel hex
    srec      Motorola S-records
    aout      Linux a.out object files
    aoutb     NetBSD/FreeBSD a.out object files
    coff      COFF (i386) object files (e.g. DJGPP for DOS)
    elf32     ELF32 (i386) object files (e.g. Linux)
    elf       ELF (short name for ELF32) 
    elf64     ELF64 (x86_64) object files (e.g. Linux)
    as86      Linux as86 (bin86 version 0.3) object files
    obj       MS-DOS 16-bit/32-bit OMF object files
    win32     Microsoft Win32 (i386) object files
    win64     Microsoft Win64 (x86-64) object files
    rdf       Relocatable Dynamic Object File Format v2.0
    ieee      IEEE-695 (LADsoft variant) object file format
    macho32   NeXTstep/OpenStep/Rhapsody/Darwin/MacOS X (i386) object files
    macho     MACHO (short name for MACHO32)
    macho64   NeXTstep/OpenStep/Rhapsody/Darwin/MacOS X (x86_64) object files
    dbg       Trace of all info passed to output stage
Isn't "-f elf" correct, then?
So, you absolutely stubbornly refuse to notice presence of 32 and 64 numbers in the output ?
 
0 members found this post helpful.
Old 04-22-2010, 12:39 PM   #5
MTK358
LQ 5k Club
 
Registered: Sep 2009
Posts: 6,443

Original Poster
Blog Entries: 3

Rep: Reputation: 723Reputation: 723Reputation: 723Reputation: 723Reputation: 723Reputation: 723Reputation: 723
But it says that "elf" is the same as "elf32"!
 
Old 04-22-2010, 12:57 PM   #6
Sergei Steshenko
Senior Member
 
Registered: May 2005
Posts: 4,481

Rep: Reputation: 454Reputation: 454Reputation: 454Reputation: 454Reputation: 454
Quote:
Originally Posted by MTK358 View Post
But it says that "elf" is the same as "elf32"!

I'm asking it again - you stubbornly refuse to see the 64 number ?
 
0 members found this post helpful.
Old 04-22-2010, 01:12 PM   #7
MTK358
LQ 5k Club
 
Registered: Sep 2009
Posts: 6,443

Original Poster
Blog Entries: 3

Rep: Reputation: 723Reputation: 723Reputation: 723Reputation: 723Reputation: 723Reputation: 723Reputation: 723
But I don't want to compile it as 64-bit! I want it to be 32-bit!
 
Old 04-22-2010, 01:44 PM   #8
Sergei Steshenko
Senior Member
 
Registered: May 2005
Posts: 4,481

Rep: Reputation: 454Reputation: 454Reputation: 454Reputation: 454Reputation: 454
Quote:
Originally Posted by MTK358 View Post
But I don't want to compile it as 64-bit! I want it to be 32-bit!
You may want whatever you want, but the rest of files are 64 bits, and the linker refuses to link 64 and 32 bit formats:

Code:
ld: i386 architecture of input file `loader.o' is incompatible with i386:x86-64 output
.

Do you see the item in red ? Would you argue with linker ?

Why do you care about the output file format ? I.e. why not doing what the linker wants from you ?
 
Old 04-22-2010, 01:53 PM   #9
MTK358
LQ 5k Club
 
Registered: Sep 2009
Posts: 6,443

Original Poster
Blog Entries: 3

Rep: Reputation: 723Reputation: 723Reputation: 723Reputation: 723Reputation: 723Reputation: 723Reputation: 723
Code:
$ nasm -f elf32 -o loader.o loader.s
$ gcc -o kernel.o -c kernel.c -Wall -Wextra -nostdlib -nostartfiles -nodefaultlibs -m32
kernel.c: In function ‘kernel_main’:
kernel.c:1: warning: unused parameter ‘mbd’
$ ld -T linker.ld -o kernel.bin loader.o kernel.o -A i386
ld: i386 architecture of input file `loader.o' is incompatible with i386:x86-64 output
ld: i386 architecture of input file `kernel.o' is incompatible with i386:x86-64 output
 
Old 04-22-2010, 02:09 PM   #10
Sergei Steshenko
Senior Member
 
Registered: May 2005
Posts: 4,481

Rep: Reputation: 454Reputation: 454Reputation: 454Reputation: 454Reputation: 454
Quote:
Originally Posted by MTK358 View Post
Code:
$ nasm -f elf32 -o loader.o loader.s
$ gcc -o kernel.o -c kernel.c -Wall -Wextra -nostdlib -nostartfiles -nodefaultlibs -m32
kernel.c: In function ‘kernel_main’:
kernel.c:1: warning: unused parameter ‘mbd’
$ ld -T linker.ld -o kernel.bin loader.o kernel.o -A i386
ld: i386 architecture of input file `loader.o' is incompatible with i386:x86-64 output
ld: i386 architecture of input file `kernel.o' is incompatible with i386:x86-64 output
You stubbornly refuse to read 'ld' manpage - see the item in red. Despite of many times you've been suggested to read.
 
0 members found this post helpful.
Old 04-22-2010, 02:52 PM   #11
Mara
Moderator
 
Registered: Feb 2002
Location: Grenoble
Distribution: Debian
Posts: 9,696

Rep: Reputation: 232Reputation: 232Reputation: 232
Moderator note: Dear Sergei, it is not really necessary to be aggressive. A simple mention of the options that cause problems would be enough.
 
Old 04-22-2010, 03:00 PM   #12
MTK358
LQ 5k Club
 
Registered: Sep 2009
Posts: 6,443

Original Poster
Blog Entries: 3

Rep: Reputation: 723Reputation: 723Reputation: 723Reputation: 723Reputation: 723Reputation: 723Reputation: 723
Because ld's output showed "i386", I assumed that that would be valid input.

I looked at the man page and I don't understand this:

Code:
       -A architecture
       --architecture=architecture
           In the current release of ld, this option is useful only for the
           Intel 960 family of architectures.  In that ld configuration, the
           architecture argument identifies the particular architecture in the
           960 family, enabling some safeguards and modifying the archive-
           library search path.

           Future releases of ld may support similar functionality for other
           architecture families.
What's the option for ld to output i386 executables?
 
Old 04-22-2010, 04:22 PM   #13
Sergei Steshenko
Senior Member
 
Registered: May 2005
Posts: 4,481

Rep: Reputation: 454Reputation: 454Reputation: 454Reputation: 454Reputation: 454
Quote:
Originally Posted by MTK358 View Post
Because ld's output showed "i386", I assumed that that would be valid input.

I looked at the man page and I don't understand this:

Code:
       -A architecture
       --architecture=architecture
           In the current release of ld, this option is useful only for the
           Intel 960 family of architectures.  In that ld configuration, the
           architecture argument identifies the particular architecture in the
           960 family, enabling some safeguards and modifying the archive-
           library search path.

           Future releases of ld may support similar functionality for other
           architecture families.
What's the option for ld to output i386 executables?

Which part of the item in red you do not understand ?

As I have already asked you, did you read to the very end output produced by

Code:
ld --help | less
?

Did you comprehend and analyze the text ? Did you do analysis WRT relevant and irrelevant to your task items ?
 
Old 04-22-2010, 04:28 PM   #14
MTK358
LQ 5k Club
 
Registered: Sep 2009
Posts: 6,443

Original Poster
Blog Entries: 3

Rep: Reputation: 723Reputation: 723Reputation: 723Reputation: 723Reputation: 723Reputation: 723Reputation: 723
I read throught it, I believe that the answer might be there, but I just don't understand it.

I read it, but I don't understand it.

I try to read documentation, but you always assume I don't. I say that I tried but I don't understand, but you keep falsely blaming me for not even trying. I'm just sick of that!
 
Old 04-22-2010, 04:30 PM   #15
Sergei Steshenko
Senior Member
 
Registered: May 2005
Posts: 4,481

Rep: Reputation: 454Reputation: 454Reputation: 454Reputation: 454Reputation: 454
Quote:
Originally Posted by MTK358 View Post
I read throught it, I believe that the answer might be there, but I just don't understand it.

I read it, but I don't understand it.

I try to read documentation, but you always assume I don't. I say that I tried but I don't understand, but you keep falsely blaming me for not even trying. I'm just sick of that!
I am asking you again, which part of

Quote:
In the current release of ld, this option is useful only for the
Intel 960 family of architectures
you do not understand ? It's a very simple question.
 
0 members found this post helpful.
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[Compile kernel] How to compile/install the modules ? frenchn00b Linux - General 1 09-06-2009 03:18 PM
Trying to patch kernel + compile, compile is looping. kripz Linux - Kernel 1 06-16-2009 06:51 AM
CLFS 5.9 - Glibc compile: suffix of object files, cannot compile Noddegamra Linux From Scratch 3 04-27-2009 12:49 AM
how to compile software for any other Linux box which is do not have compile? hocheetiong Linux - Newbie 4 03-06-2009 04:35 PM
ntop compile/post-compile problem? tjb Linux - Software 3 12-28-2004 04:22 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 01:07 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration