Question:
How can I take linux based C++ source code and compile it to work on windows?
Richard S
2007-04-06 21:56:09 UTC
I obviously can't compile it in VC++ 8 because several include files are missing, so how would I go about compiling a linux program for windows? And what compiler would I need to start?
Four answers:
2007-04-09 07:47:39 UTC
Use dev C/C++. It should work fine.



RJ
csanon
2007-04-07 05:20:24 UTC
There's a potential misunderstanding from previous answers, so here are my points.



As is the case with most non-trivial programs, if you're program in question relies on OS or hardware specific code, rather than portable and standard C++, you need to either simulate that platform, or you need to port the code.



So if you want Linux code working natively on Windows, you need to recode it (port it) to work on Windows. Examples of being out of luck: use fork in the prog, and you need to port that portion in Windows. There is no forking in Windows.



The other alternative is to simulate a Linux environment. One of the ways is to install Cygwin. Cygwin is basically a massive Linux-like environment that can run various Linux programs. It's a giant emulation layer.



No, Dev-C++ won't work. It uses MinGW, which compiles to a windows binary using MS runtime libraries. Besides, how is a windows prog going to do something like fork?



EDIT: No, you're out luck on Windows native. For example, unistd.h knocks you out of the Windows world. No, you can't get the libraries for Windows. They are for Linux only.
capp
2007-04-07 05:09:25 UTC
might want to look into installing Cygwin onto the Windows machine. It has GNU libraries that would be on a Linux box.

I usually install it and set cygwin/bin in my windows path so that all the commands/programs can be used in a windows command shell. gcc G++ is all there. good luck. Dev-C++ is a free C++ compiler also, but I don't know about the libraries.
RideYukon164
2007-04-07 05:04:24 UTC
If you're using linux-specific libraries you're pretty much out of luck.

If you're using general c++ libraries, your compiler probably just can't find them.



In future, you could try using Java as it was designed to be ported to any operating system with minimal changes to the code.


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...