LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 08-14-2004, 12:03 AM   #1
dtheorem
Member
 
Registered: Sep 2003
Location: Winnipeg, MB, CA
Distribution: LinuxMint
Posts: 101

Rep: Reputation: 15
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.
 
Old 08-14-2004, 12:18 AM   #2
b0ng
LQ Newbie
 
Registered: Aug 2004
Location: Location??? Where I am is top secret, if I tell you, I have to kill you.
Distribution: College, Slack
Posts: 24

Rep: Reputation: 15
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.
 
Old 08-14-2004, 01:51 AM   #3
max_sipos
Member
 
Registered: Jul 2004
Posts: 96

Rep: Reputation: 15
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/
 
Old 08-14-2004, 02:28 AM   #4
onnyloh
Member
 
Registered: Nov 2002
Posts: 57

Rep: Reputation: 15
maybe this can be achieve using wine?
 
Old 08-14-2004, 04:48 AM   #5
barisdemiray
Member
 
Registered: Sep 2003
Location: Ankara/Turkey
Distribution: Slackware
Posts: 155

Rep: Reputation: 30
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.
 
Old 08-14-2004, 06:04 AM   #6
max_sipos
Member
 
Registered: Jul 2004
Posts: 96

Rep: Reputation: 15
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.
 
Old 08-14-2004, 08:38 AM   #7
barisdemiray
Member
 
Registered: Sep 2003
Location: Ankara/Turkey
Distribution: Slackware
Posts: 155

Rep: Reputation: 30
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
 
Old 08-14-2004, 08:45 AM   #8
max_sipos
Member
 
Registered: Jul 2004
Posts: 96

Rep: Reputation: 15
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
 
Old 08-14-2004, 10:36 AM   #9
jlliagre
Moderator
 
Registered: Feb 2004
Location: Outside Paris
Distribution: Solaris 11.4, Oracle Linux, Mint, Debian/WSL
Posts: 9,789

Rep: Reputation: 492Reputation: 492Reputation: 492Reputation: 492Reputation: 492
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.
 
Old 08-14-2004, 04:03 PM   #10
deiussum
Member
 
Registered: Aug 2003
Location: Santa Clara, CA
Distribution: Slackware
Posts: 895

Rep: Reputation: 32
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...
 
Old 08-16-2004, 01:41 AM   #11
jlliagre
Moderator
 
Registered: Feb 2004
Location: Outside Paris
Distribution: Solaris 11.4, Oracle Linux, Mint, Debian/WSL
Posts: 9,789

Rep: Reputation: 492Reputation: 492Reputation: 492Reputation: 492Reputation: 492
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.
 
Old 08-16-2004, 07:43 AM   #12
mhearn
LQ Guru
 
Registered: Nov 2002
Location: Durham, England
Distribution: Fedora Core 4
Posts: 1,565

Rep: Reputation: 57
I cross-compile windows EXEs all the time, mostly test cases for Wine development.
 
Old 08-16-2004, 09:20 AM   #13
jlliagre
Moderator
 
Registered: Feb 2004
Location: Outside Paris
Distribution: Solaris 11.4, Oracle Linux, Mint, Debian/WSL
Posts: 9,789

Rep: Reputation: 492Reputation: 492Reputation: 492Reputation: 492Reputation: 492
What tools are you using to do it ?
 
Old 08-16-2004, 10:43 AM   #14
deiussum
Member
 
Registered: Aug 2003
Location: Santa Clara, CA
Distribution: Slackware
Posts: 895

Rep: Reputation: 32
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.
 
Old 08-16-2004, 12:25 PM   #15
jlliagre
Moderator
 
Registered: Feb 2004
Location: Outside Paris
Distribution: Solaris 11.4, Oracle Linux, Mint, Debian/WSL
Posts: 9,789

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

(from Cambridge Advanced Learner's Dictionary)
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
C compiler cannot create executables martincho Linux - Software 3 10-01-2004 07:04 PM
C compiler cannot create executables w0lv3rin3 Linux - Software 4 08-07-2004 10:44 AM
C++ compiler cannot create executables IceStorm Linux - Newbie 6 06-14-2004 01:45 AM
Cannot create executables under 9.1 pyrombca Slackware 5 12-29-2003 06:48 PM
C compiler cannot create executables... Sfpiano Linux - Software 9 12-11-2003 10:28 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 12:38 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration