loader.o:file format not recognised

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
Sampiedev007
Posts: 3
Joined: Mon Oct 17, 2011 6:04 am

loader.o:file format not recognised

Post by Sampiedev007 »

hi everyone ,
i m making an os, it's the first time i use C++ to create an os(i choose it because it's the language that i m more experienced than the others).
i search on the net to find a tutorial from where i began.
i did the part code : my project is composed of (temporarily) : VideoMemory.h and CPP , Kernel.cpp loader.asm commun.h .
i compile loader.asm with nasm, and the others file with gcc: i used this command to make the .o: nasm -o aout loader.asm loader.o
i got .o files and i make my linker :

Code: Select all

OUTPUT_FORMAT("binary")
ENTRY(start)
SECTIONS
{
    .text 0x100000 :
    {
        code = .; _code = .; __code = .;
        *(.text)
        . = ALIGN(4096);
    }

    .data :
    {
        data = .; _data = .; __data = .;
        *(.data)
        . = ALIGN(4096);
    }

    .bss :
    {
        bss = .; _bss = .; __bss = .;
        *(.bss)
        . = ALIGN(4096);
    }

    end = .; _end = .; __end = .;
}
i link them using ld -T Linker.ld -o Kernel.bin loader.o Kernel.o VideoMemory.o
but i get this error :
loader.o: file not recognized: File format not recognized

thx for your help
User avatar
Solar
Member
Member
Posts: 7615
Joined: Thu Nov 16, 2006 12:01 pm
Location: Germany
Contact:

Re: loader.o:file format not recognised

Post by Solar »

Using Windows?

Not using a cross-compiler?

Try "file loader.o" and check the output. If you see something like "COFF" or "PE", you should refer to the Wiki, more specifically GCC Cross-Compiler.
Every good solution is obvious once you've found it.
User avatar
Solar
Member
Member
Posts: 7615
Joined: Thu Nov 16, 2006 12:01 pm
Location: Germany
Contact:

Re: loader.o:file format not recognised

Post by Solar »

Belay that order.
Sampiedev007 wrote:i used this command to make the .o: nasm -o aout loader.asm loader.o
Take this in isolation:

Code: Select all

nasm -o aout loader.asm loader.o
Hint: There is something severely wrong about that line. Check NASM documentation.
Every good solution is obvious once you've found it.
User avatar
Chandra
Member
Member
Posts: 487
Joined: Sat Jul 17, 2010 12:45 am

Re: loader.o:file format not recognised

Post by Chandra »

Solar wrote:

Code: Select all

nasm -o aout loader.asm loader.o
Hint: There is something severely wrong about that line. Check NASM documentation.
For the sake of simplicity,

Code: Select all

nasm -f aout loader.asm -o loader.o
And no, that's not spoon-feeding. His assembler didn't complain on that so, I'd assume that must be a typing error.

Besides, use a Cross-Compiler.
Programming is not about using a language to solve a problem, it's about using logic to find a solution !
User avatar
Solar
Member
Member
Posts: 7615
Joined: Thu Nov 16, 2006 12:01 pm
Location: Germany
Contact:

Re: loader.o:file format not recognised

Post by Solar »

-f aout?

Really?
Every good solution is obvious once you've found it.
User avatar
Chandra
Member
Member
Posts: 487
Joined: Sat Jul 17, 2010 12:45 am

Re: loader.o:file format not recognised

Post by Chandra »

Solar wrote:-f aout?

Really?
Yes, of course. You seem to find a problem on that, don't you?
Programming is not about using a language to solve a problem, it's about using logic to find a solution !
User avatar
Solar
Member
Member
Posts: 7615
Joined: Thu Nov 16, 2006 12:01 pm
Location: Germany
Contact:

Re: loader.o:file format not recognised

Post by Solar »

Not authoritatively, no. I just would've expected either ELF or binary, not an executable format...?!?
Every good solution is obvious once you've found it.
User avatar
Chandra
Member
Member
Posts: 487
Joined: Sat Jul 17, 2010 12:45 am

Re: loader.o:file format not recognised

Post by Chandra »

Solar wrote:Not authoritatively, no. I just would've expected either ELF or binary, not an executable format...?!?
Oh! That's a valid logic :)

Since things are later linked with the kernel, it won't matter anyway(other than linker bumping out with the error: Can't recognize file format :wink:)
Programming is not about using a language to solve a problem, it's about using logic to find a solution !
User avatar
Solar
Member
Member
Posts: 7615
Joined: Thu Nov 16, 2006 12:01 pm
Location: Germany
Contact:

Re: loader.o:file format not recognised

Post by Solar »

...which is exactly what Sampiedev007 is seeing. So I would start by assembling loader.asm to object file, not executable. (I haven't worked with NASM, but I would guess it's creating a fully-linked executable here, startup code and everything. As a linker, I would balk at linking an executable into another executable, too. ;-) )
Every good solution is obvious once you've found it.
User avatar
Chandra
Member
Member
Posts: 487
Joined: Sat Jul 17, 2010 12:45 am

Re: loader.o:file format not recognised

Post by Chandra »

Solar wrote:...which is exactly what Sampiedev007 is seeing.
I've set-up the cross compiler that spits out the elf binaries but still is able to link the aout file-format. It doesn't complain on that so I'd say the actual problem is with the compiler tool-chain.
Solar wrote:So I would start by assembling loader.asm to object file, not executable.
That's a better approach, though.
Programming is not about using a language to solve a problem, it's about using logic to find a solution !
User avatar
Solar
Member
Member
Posts: 7615
Joined: Thu Nov 16, 2006 12:01 pm
Location: Germany
Contact:

Re: loader.o:file format not recognised

Post by Solar »

Chandra wrote:...so I'd say the actual problem is with the compiler tool-chain.
Just because you found an error doesn't mean you've found the error. :wink:
Every good solution is obvious once you've found it.
Post Reply