PDA

View Full Version : Linux to Windows



PING
11-26-2006, 02:11 AM
If i compile and make an executable on linux, is it possible for it to be executed on windows, ive tried it, but i get an error that the file has encountered an illegal instruction. The file is just a simple hello world program including just one printf statement.

Salem
11-26-2006, 03:12 AM
You need to run a compiler which generates windows executables on your Linux box.
Does dev-c++ work within WINE I wonder?

What you're basically talking about is a cross-compiler, which runs on machine 'a', but produces executables for machine 'b'. Since in your case, 'b' is a windows machine with many compilers readily available, true linux-to-windows cross compilers are pretty rare.
Mostly people just copy the source across and compile it.

PING
11-26-2006, 04:10 AM
Umm..but well, if i compile things using linux using say posix threads and sockets, i want to port it to windows..would that be possible ?? i ll try getting devcpp to work on wine.

Salem
11-26-2006, 04:25 AM
Well you still need to make sure that the code you compile for windows is valid windows source code (all the correct API calls for example), no matter where you compile it.

It won't magically fix your posix threads and sockets into win32 API for you.

PING
11-26-2006, 04:47 AM
Okay, i tried using devcpp on linux, it installs properly, but i dont seem to be able to run it..so, basically, i ll have to understand windows based multithreading and sockets if i want to make something that can work on windows?

Salem
11-26-2006, 04:53 AM
You have to write the code which you would write if you were sitting at a windows machine with dev-c++ installed.

Like network programs begin and end with wsaStartup() and wsaCleanup()

Installing dev-c++ via WINE on your linux box saves some walking about (perhaps), but you still need to get over to the windows box to test the executable.

PING
11-26-2006, 05:01 AM
Yes, porting the network part would be ok i guess, not much of a difference, but the threading part would mean that id have to do windows based multithreading right? i remember adrian had written a tutorial on this..i ll try n search for it, thank you for the help :)

fnoyan
11-26-2006, 07:59 AM
As Salem said, lack of libraries makes it difficult to port some applications to windows. MAybe you should search msdn for porting applications from unix to windows. I know there is such a section exists but not sure if it can satisfy you!

PING
11-26-2006, 01:42 PM
I know there is such a section exists but not sure if it can satisfy you
You mean on msdn? can you give me a link to the one you are talking about? i ll search for it nonetheless..

vart
11-26-2006, 01:50 PM
something like that
http://msdn2.microsoft.com/en-us/library/y23kc048(vs.80).aspx

CornedBee
11-26-2006, 02:56 PM
Boost contains both threading and (in the upcoming 1.34 release, I think, but I'm not sure) networking libraries that work on both Windows and various Unix-likes.
The networking library is called ASIO, you can also get it at asio.sourceforge.net.

PING
11-26-2006, 11:51 PM
Okay, thankyou..will look into it :)

Cactus_Hugger
11-27-2006, 12:32 AM
pthreads (http://sourceware.org/pthreads-win32/) is available on Windows. (I hope that's where I got my pthread's library from...)
As for sockets, good luck. Depending on the code, it can be as simple as adding in the calls that Salem mentioned or much more complex. If you have any specific problems, that's what these boards are for.

I sort of looked at asio and started to write my own sockets wrapper... but it's preference.

blank
12-09-2006, 07:07 PM
I think what you want is mingw (http://www.mingw.org/docs.shtml), I believe it has a cross compiler. For information on cross compiling, you can google 'mingw cross compile' as I did. I found one article, although it's supposedly for WxWindows (The article), it should still work for you: here (http://www.wxwidgets.org/wiki/index.php/Install_The_Mingw_Cross-Compiler). Hope that helps, sorry if that's not what you meant.