LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   create windows executables in linux? (https://www.linuxquestions.org/questions/programming-9/create-windows-executables-in-linux-217382/)

dtheorem 08-14-2004 12:03 AM

create windows executables in linux?
 
Why would anyone ever want to do this? I don't know. But is there anyway to compile a C++ program in linux, but compile it as a Windows .EXE? Personally, I don't need to do this, but if it exists, I'd like to know about it.

b0ng 08-14-2004 12:18 AM

I am pretty sure there is no way to do that simply because, the binaries on windows an Unix/Linux are different. Try compiling a program on linux, it won't work, if you take it over to a windows box. Which is why when you go to a site and download something, it has different binaries for windows, and linux.

max_sipos 08-14-2004 01:51 AM

There is a way to compile windows binaries on GCC, at least there used to be (darn, I can't remember now).
ahh there: http://www.mingw.org/

onnyloh 08-14-2004 02:28 AM

maybe this can be achieve using wine?

barisdemiray 08-14-2004 04:48 AM

Quote:

Originally posted by onnyloh
maybe this can be achieve using wine?
Yes i know like that too.. Also there are examples like Kylix (it's a Linux port of Delphi cross-compiled with wine).

You can port a winblows program to Linux by compiling it's source code but you cannot build winblows executables on Linux. As you know there are no library required by a winblows executables in Linux. If you would use SetTimer(), where can you get the internal source of this function.. May be there are hobby projects for this purpose but i think it would be waste of time.

max_sipos 08-14-2004 06:04 AM

You _CAN_ build windows executables on linux. You _DO NOT_ need the DLLs in order to link the libraries, you only need the header files and .LIB files (which actually only contain bare requirements for importing functions, i.e. you can easily build them using implib or something like that). The reason is that EXEs have a section stating a list of DLLs including the function names.

I am oversimplifying the description now, see Windows PE format description and COFF format description. Also, see link I posted earlier in this thread.

barisdemiray 08-14-2004 08:38 AM

Quote:

Originally posted by max_sipos
You _CAN_ build windows executables on linux. You _DO NOT_ need the DLLs in order to link the libraries, you only need the header files and .LIB files (which actually only contain bare requirements for importing functions, i.e. you can easily build them using implib or something like that). The reason is that EXEs have a section stating a list of DLLs including the function names.

I am oversimplifying the description now, see Windows PE format description and COFF format description. Also, see link I posted earlier in this thread.

Wow.. sorry about that. What i mean was similar to that you mentioned about (we don't have included function's binaries (LIBs)) but i've not heard about the project. Additionaly, it's still waste of time according to me.. :-D

max_sipos 08-14-2004 08:45 AM

Yeah, I realize that you meant more about compiling win32 source and making it work on linux :) ... Yeah it's definitely a waste of time building EXE on linux, although I think some ppl use it in order to develop without having to pay for Visual Studio etc., they probably use it on native windows machines in cygwin or something of the sort. I remember that there's also the lcc compiler (implementation described in a great book about making compilers, search for lcc on amazon), and it has a port for windows lcc-win32 which is free - on the other hand, it's limited to C only.


---
Maksim Sipos

jlliagre 08-14-2004 10:36 AM

Technically, there is no reason not being able to build a binary for one architecture O/S from another architecture O/S. This is called cross-compiling.

There are platforms where it is the most used or even the only way to do it (developers writing programs for telephones, handheld devices, game consoles, digital cameras, ... usually do not use them as development platform :) )

The gnu compiler suite is built with cross compilation support, meaning that you can build binaries for a large choice of CPUs and a large choice of binary format.
Unfortunately, there are few packaged cross compilers, so you usually need to build yourself the one you need, and this is a painful experience, as it isn't the well supported area of the gnu tools.
Linux to win32 cross compilation is a common need as linux is a frequent developer's platform while windows is, whatever we like, the widely used O/S on PCs.
Unfortunately, this cross compilation using a mingw port to linux is no more maintained by its author (http://members.telering.at/jessich/mingw/) but there are certainly other efforts.

Finally, I disagree about the fact that cross-compiling is a waste of time. Actually, it can save a lot of time and money to a developer who do not need to buy the target O/S license, and boot a platform running it, but want to increase his software audience anyway.

deiussum 08-14-2004 04:03 PM

Aside from cross-compiling, which has already been mentioned, some languages like Java, C#, etc. compile down to a standard binary format that can theoretically be used on multiple platforms without recompiling. For instance, I have compiled some C# apps with DotGNU, and run the resulting exe directly on Windows. I have also compiled C# apps in Windows using Visual Studio .Net, and had that same exe run on Linux using the DotGNU tools...

jlliagre 08-16-2004 01:41 AM

Cross compiling was already mentioned, but I (wrongly) thought it was out of context as it only mentioned delphi.
The original question was about C++, for which there are no virtual machines like Java and C# ones, AFAIK. It's true that these languages share similarities between themselves and C++ though.
Running Java classes on multiple platforms is more than a theory, but is demonstrated since at least 8 years. One can argue that this isn't really cross-platform execution, as in fact Java and C# classes are not at all portable between platforms, but instead are only usable by a single platform which is their virtual machine.
The virtual machine is the real portable code there.

mhearn 08-16-2004 07:43 AM

I cross-compile windows EXEs all the time, mostly test cases for Wine development.

jlliagre 08-16-2004 09:20 AM

What tools are you using to do it ?

deiussum 08-16-2004 10:43 AM

Quote:

Originally posted by jlliagre
Running Java classes on multiple platforms is more than a theory, but is demonstrated since at least 8 years. One can argue that this isn't really cross-platform execution, as in fact Java and C# classes are not at all portable between platforms, but instead are only usable by a single platform which is their virtual machine.
The virtual machine is the real portable code there.

When I said theoretically, I didn't mean to say that you CAN'T run it on multiple platforms. I meant that not ALL Java/C# projects will necessarily run on all platforms. For instance, if you write a Java app that relies on a Java package that only exists for Windows or Linux (The old J++ classes come to mind...), you aren't going to necesarily be able to just plop the new .class file into a different OS and be able to run it.

The same for C#... there are some classes in Visual C# .Net that haven't yet been implemented in DotGNU, so if you use those classes, you aren't going to be able to directly run the .exe on Linux.

jlliagre 08-16-2004 12:25 PM

Definition: theoretically
adverb: in a way that obeys some rules but is not likely:
It is theoretically possible.

(from Cambridge Advanced Learner's Dictionary)


All times are GMT -5. The time now is 06:02 PM.