Author Topic: NASM Linux assembly - Windows object  (Read 19582 times)

Offline berrabbit

  • New Member
  • Posts: 1
NASM Linux assembly - Windows object
« on: August 16, 2010, 02:50:26 PM »
    Nasm assembly and program execution working fine for me on my box in linux (Ubuntu).  Link editor and gdb fine too.   More, I am able to zip a program object (binary) and send it as a mail attachment to person#1.  Person#1 is running a linux os and can get the mail, unzip it, and execute my object just fine.  Person#2 and person#3 are running Microsoft os.  They can unzip the attachment but then problems.

    What do I need to do on my linux box to my source code, the NASM assembler, or ld to create an executable object that is Windows compatible so I can send the object to person #2 and #3?
Thanks,

Offline Keith Kanios

  • Full Member
  • **
  • Posts: 383
  • Country: us
    • Personal Homepage
Re: NASM Linux assembly - Windows object
« Reply #1 on: August 16, 2010, 03:32:36 PM »
A couple of options for you:

1.) Download a cross-compiler that can link a Win32 binary, e.g. MinGW
2.) Grab Wine and a linker such as GoLink so that you can use NASM to output a Win32 object for linking, with regard to the appropriate/equivalent shared (DLL) libraries.

However, this is assuming that you are using code that is fairly neutral, mostly meaning CDECL and the standard C library, i.e. msvcrt.dll on Windows. If you are using the Linux syscall (INT 0x80) API, then forget it... those people will simply need a distribution of Linux.

A decent option for person #2 and #3 to run Linux stuff on Windows: andLinux.

Offline Frank Kotler

  • NASM Developer
  • Hero Member
  • *****
  • Posts: 2667
  • Country: us
Re: NASM Linux assembly - Windows object
« Reply #2 on: August 16, 2010, 04:09:18 PM »
Well... take a look at this:

http://forum.nasm.us/index.php?topic=810.0

First, notice that his source code calls C library functions - there are no Linux-specific system calls. Note that "main", "printf", etc. don't have underscores on 'em - Linux doesn't use 'em (except _start). Note that Brainiac's makefile adds "--prefix _" to Nasm's command line - this adds underscores to everything declared "global" (or extern), which Windows needs. Otherwise you'd have to change your source code.

Nasm will easily create linkable object files for either system - "-f elf32" or "-f win32" - but your Linux ld is expecting ELF linkable objects, and produces ELF executables. Windows needs a PE ("portable executable") executable format, and I don't think there's any way to get one out of Linux ld. But the MinGW package will run on Linux and produce what you want... at least according to Brainiac. I'd try it just the way he says, and see how it goes.

If your source code doesn't stick to the C library, and uses Linux-specific system calls, you'll have to convert them to equivalent Windows APIs. Probably easier to persuade person #2 and person #3 to switch to Linux! :)

There are alternatives... the HLA standard library exists for both Linux and Windows, too. I'd stick to the C library...

Best,
Frank


Offline Rob Neff

  • Forum Moderator
  • Full Member
  • *****
  • Posts: 429
  • Country: us
Re: NASM Linux assembly - Windows object
« Reply #3 on: August 16, 2010, 04:13:32 PM »
Probably easier to persuade person #2 and person #3 to switch to Linux! :)

Or even try a Live CD as a gentle introduction :)