[Problem] Problem with cygwin ld and ASM+C file/format

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.
Locked
Threadcore
Posts: 6
Joined: Wed Nov 23, 2011 6:20 am

[Problem] Problem with cygwin ld and ASM+C file/format

Post by Threadcore »

Hello

I am a bit confused about the build environment for creating an own OS. At the moment I use NASM and cygwin (gcc-4 and ld).

System: Widnows 7 x64
Target Own 32 bit OS

Files:

Code: Select all

build.bat = Compiles the files and call link.txt
link.txt = Links kernel32.asm and kernel.c
kernel32.asm = Assembler file
kernel.c = Dummy C file with a main 
Buildfile:

Code: Select all

nasmw -f aout -o kernel32.obj kernel32.asm
gcc-4 -ffreestanding -c -o ckernel.obj kernel.c
ld -T link.txt -o c32kernel.bin
Linkfile:

Code: Select all

OUTPUT_FORMAT("binary")
INPUT(kernel32.obj ckernel.obj)
ENTRY(start)
SECTIONS
{
  .text  0x10200 : {
    code = .; _code = .; __code = .;
    *(.text)
    . = ALIGN(1);
  }
  .data  : {
    data = .; _data = .; __data = .;
    *(.data)
    . = ALIGN(1);
  }
  .bss  :
  {
    bss = .; _bss = .; __bss = .;
    *(.bss)
    . = ALIGN(1);
  }
  end = .; _end = .; __end = .;
}
Now I will link the assembler and a c file and create a binary, but I become an error:

Code: Select all

kernel32.obj: file not recognized: File format not recognized
When I change the aout to elf, I habe the problem with the "cannot perform PE operations". I read here and in the Internet (http://wiki.osdev.org/Cannot_perform_PE ... on-PE_file) about this error (sometimes they use an other format and have the PE error). I read something about, that obj is only for 16 bit code, is this really true ?

Best regards
User avatar
Solar
Member
Member
Posts: 7615
Joined: Thu Nov 16, 2006 12:01 pm
Location: Germany
Contact:

Re: [Problem] Problem with cygwin ld and ASM+C file/format

Post by Solar »

Threadcore wrote:I read something about, that obj is only for 16 bit code, is this really true ?
No.

The Cygwin compiler generates Windows binaries, which is usually not what you want.

The link to the solution is actually in your question.
Every good solution is obvious once you've found it.
Nable
Member
Member
Posts: 453
Joined: Tue Nov 08, 2011 11:35 am

Re: [Problem] Problem with cygwin ld and ASM+C file/format

Post by Nable »

I read something about, that obj is only for 16 bit code, is this really true ?
No, afaik, .OBJ files contain COFF (or MS COFF), it's not limited to 16 bit code.
User avatar
AJ
Member
Member
Posts: 2646
Joined: Sun Oct 22, 2006 7:01 am
Location: Devon, UK
Contact:

Re: [Problem] Problem with cygwin ld and ASM+C file/format

Post by AJ »

Locked before the flaming starts. As Solar said, the answer to the question is in the original post. Please read the wiki topic linked to in your post. As far as the object files are concerned, I suggest a healthy dose of applications programming and playing around with your toolchain as the next step.

Cheers,
Adam
Locked