Yahoo Answers is shutting down on May 4th, 2021 (Eastern Time) and the Yahoo Answers website is now in read-only mode. There will be no changes to other Yahoo properties or services, or your Yahoo account. You can find more information about the Yahoo Answers shutdown and how to download your data on this help page.

How do I cross-link on Linux?

I have a computer with both Windows 7 and Linux Mint 13. I'm learning to program for Windows, but I use Linux for most of my stuff. I'm looking to assemble and link on Linux so I don't have to reboot into Windows every time I want to work on my program. I'm sure the basic stuff I'm doing can be tested with Wine. I can use NASM on Linux, just like in Windows, to assemble my code into a .obj file, but I don't know how to link the DLLs and make a .exe on Linux. On Windows, I use alink, but what do I do on Linux? Can the GNU Linker (ld) do this? If so, how? I don't want to use a virtual machine, because I don't think I will be able to activate Windows, which would make me have to reinstall every 30 days.

Also, please don't ***** about me using assembly language. I'm tired of people telling me to just use C/C++. I'm not interested in that right now.

Update:

Does anyone know what parameters i need to use with ld in order to produce the Windows .exe format?

Update 2:

Does anyone know what parameters i need to use with ld in order to produce the Windows .exe format?

1 Answer

Relevance
  • Anonymous
    7 years ago
    Favorite Answer

    EDIT:

    Are you using the Linux LD program or the LD Windows PE port version? The Windows PE port has additional commands:

    http://linux.die.net/man/1/ld

    The Windows LD port has similar commands to Microsoft's link.exe program, so you should be able to just specify your .obj file(s) and the required Windows import libraries and then just use one of these command-line parameters.

    --subsystem:Windows (for GUI programs)

    or

    --subsystem:console

    Note: There is no mention of resource linking, so you may need to use a separate tool to add resources (icons, version information, etc.) after you build the .exe file.

    --------

    First, I should say that anyone who tells you not to use assembly language is a clueless idiot. Bring them to me and I'll prove that they are MORONS who shouldn't be programming. I know what I'm talking about, since I've been programming for over 30 years and have seen programming degenerate into complete crap since the end of the '80's. The '90's is where OOP became popular and that was due to a large number of COMPLETE IDIOTS who obviously cannot evaluate anything regarding programming.

    These days, it only takes several seconds for me to determine if someone should be programming or not --and I'll even give them a handicap by not giving them the "What do you think about OOP?" question.

    Okay, unless Linux compilers & assemblers don't use a common object file format (that would be really stupid), then you should be able to use any linker. You might already have the 'ld' linker program on your Linux system, so use that. On Windows, there are actually 2 .obj/library formats. The old OMF format and the newer COFF format. Borland compilers use the older format, but they have a conversion program.

    Wine should work with any regular Windows program which doesn't use special undocumented API functions, and possibly the chicken-brained programming aspects of Windows such as COM objects.

    Now, as far as writing machine code programs for Windows, I really suggest that you use MASM32. In fact, if you're going to write Windows programs, then you should stick with the traditional Windows programming tools (e.g. Microsoft or Borland for writing C/C++ programs). You will find more programming examples, source code, and support.

    For Windows assembly language programming, I suggest that you download the MASM32 package. You will have to see if MASM's assembler, linker, and resource compiler programs work with Wine though.

    http://www.masm32.com/

    Next, get the Windows API SDK from Microsoft's web site. It includes C/C++ header files and import libraries, some programming tools, example code, a C/C++ compiler & linker, and most importantly: the documentation for almost all of the Windows API functions. (The smart Linux programmers would be envious of this kind of programming package.) I don't know if the insanely bloated, slow API documentation reader program in the SDK will work with Wine though.

    Next, if you don't have this book, then buy it or (*cough*) download it to get started with Windows programming:

    http://www.charlespetzold.com/pw5/

    (To illustrate the degradation of Windows programming, Petzold's 2 earlier programming books on Windows 95 and 16 bit Windows 3.1 were actually better. Then he capped it off by writing a book on Windows programming with C#, which is a completely idiotic programming language.)

    Even though the book is written for C, you can do what I did and just translate the C code to assembly language. (I learned Windows 3.1 programming with Petzold's book, using assembly language).

    IMPORTANT things to know:

    -You don't have to mess with the selectors (e.g. CS, DS, SS, etc.) since you're working with the flat memory model. FS is used for certain things like exception handling, but you can find more info on the internet. You don't have to bother with FS, unless you really want to.

    -When writing any public functions or callbacks which may be accessed by other Windows programs or Windows, save the ESI, EDI, and EBX registers.

    -The API functions use the 'standard call' calling method. It is basically a combination of C/C++ and PASCAL function calling conventions. The function names are case-sensitive, you push the parameters on the stack from right to left (like C/C++), and the function itself cleans up the stack (like PASCAL). MASM32 has high level language calling support, so calling Windows API functions is easy.

    Example:

    invoke ExitProcess,0 ;Standard program exit function which returns 0

Still have questions? Get your answers by asking now.