How can i link Linux elf file on Win32 using ld???

Programming, for all ages and all languages.
Post Reply
teedev
Posts: 2
Joined: Tue Oct 27, 2009 9:33 pm

How can i link Linux elf file on Win32 using ld???

Post by teedev »

When i linking object file into elf (Using Win32) it show this error

Code: Select all

..\..\MinGW\bin\ld: unrecognised emulation mode: elf_i386
Supported emulations: i386pe
how can i set ld to support elf_i386 ???


thank you.
teedev
Posts: 2
Joined: Tue Oct 27, 2009 9:33 pm

Re: How can i link Linux elf file on Win32 using ld???

Post by teedev »

Ok! my problem are fixed.
while wait for answer, i still searched 2 days how to link it :)

and get this link http://cygwin.com/ml/cygwin/2006-11/msg00323.html

i forgot using 'objcopy' (never use it)
-------------
my linking code (fixed)

using on win32

Code: Select all

fasm kernel.asm
ld  -Tlink.ld  -o  kernel.out  kernel.o
objcopy -I elf32-i386 kernel.out kernel
and my code can execute!!! :mrgreen:

thank. __/\__
Tosi
Member
Member
Posts: 255
Joined: Tue Jun 15, 2010 9:27 am
Location: Flyover State, United States
Contact:

Re: How can i link Linux elf file on Win32 using ld???

Post by Tosi »

Build a cross compiler. It will save you problems later.
User avatar
Love4Boobies
Member
Member
Posts: 2111
Joined: Fri Mar 07, 2008 5:36 pm
Location: Bucharest, Romania

Re: How can i link Linux elf file on Win32 using ld???

Post by Love4Boobies »

You mean cross-Binutils.
"Computers in the future may weigh no more than 1.5 tons.", Popular Mechanics (1949)
[ Project UDI ]
Tosi
Member
Member
Posts: 255
Joined: Tue Jun 15, 2010 9:27 am
Location: Flyover State, United States
Contact:

Re: How can i link Linux elf file on Win32 using ld???

Post by Tosi »

Love4Boobies wrote:You mean cross-Binutils.
Both should be built, since using a host compiler with a cross-linker and assembler sounds like a Bad Idea.
User avatar
Love4Boobies
Member
Member
Posts: 2111
Joined: Fri Mar 07, 2008 5:36 pm
Location: Bucharest, Romania

Re: How can i link Linux elf file on Win32 using ld???

Post by Love4Boobies »

Why are you assuming he's using a compiler?
"Computers in the future may weigh no more than 1.5 tons.", Popular Mechanics (1949)
[ Project UDI ]
Tosi
Member
Member
Posts: 255
Joined: Tue Jun 15, 2010 9:27 am
Location: Flyover State, United States
Contact:

Re: How can i link Linux elf file on Win32 using ld???

Post by Tosi »

Love4Boobies wrote:Why are you assuming he's using a compiler?
I just reflexively assumed he was, as it makes sense to me that anybody using assembly (i.e., binutils only or binutils + nasm or some other assembler) would know what they are doing.
User avatar
Love4Boobies
Member
Member
Posts: 2111
Joined: Fri Mar 07, 2008 5:36 pm
Location: Bucharest, Romania

Re: How can i link Linux elf file on Win32 using ld???

Post by Love4Boobies »

I didn't necessarily mean he was interested in GAS either. Maybe he just has the object files and wished to link them. After all, we're in the Everything Else forum.
"Computers in the future may weigh no more than 1.5 tons.", Popular Mechanics (1949)
[ Project UDI ]
User avatar
arabasso
Member
Member
Posts: 27
Joined: Thu Jul 10, 2008 9:41 am

Re: How can i link Linux elf file on Win32 using ld???

Post by arabasso »

Exactly, you can use objcopy to create a binary format other than PE (when you use it, you can leave your linker script without binary type information).

Another is about the name of functions and variables, which adds a MinGW "_" before the name of each function. If you do not want that "junk" in your kernel code (and also make your code more compatible with a possible build in Linux), just pass the parameter "-fno-underscore" for GCC.
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: How can i link Linux elf file on Win32 using ld???

Post by Combuster »

And you'll end up adding options and more options until you covered all hidden "features" of mingw that will pop up over time, until you find that that particular compiler is inherently broken to do your work.

The cross-compiler is the recommended solution for a reason.
"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 ]
User avatar
Love4Boobies
Member
Member
Posts: 2111
Joined: Fri Mar 07, 2008 5:36 pm
Location: Bucharest, Romania

Re: How can i link Linux elf file on Win32 using ld???

Post by Love4Boobies »

For the second time, cross-Binutils. :)
"Computers in the future may weigh no more than 1.5 tons.", Popular Mechanics (1949)
[ Project UDI ]
Post Reply