Can I use C++ Sourcecode written on a linux computer on a windows computer?
2011-06-25 16:31:09 UTC
I'm writing code for class, and I already have a C++ compiler on here. So could it just as easily be compiled from a windows computer?
Five answers:
Shadow Wolf
2011-06-25 17:08:24 UTC
If they are command line or console only and not X Windows programs, then yes they can be compiled under Windows. Download a copy of DJGPP which will generally compile Linus or *nix programs without any changes and run them under Windows. Most or all of the work has been done for you in the DJGPP libraries. You can also get a Borland C/C++ style IDE called RHIDE that works with DJGPP. There are some possible problems though.
DJGPP is a 32 bit compiler that uses a 16 bit stub. As such, under Win7 64 bit, you need the XP emulator or DOSbox to run DJGPP and DJGPP compiled programs. The XP emulator is only available for Win7-64 Ultimate and a couple other versions. Use DOSbox with Win7-64 home edition and some of the other 64 bit OS's.
Programs that use the DJGPP libraries may not be compatible with Microsoft compilers or Linux if any of the Borland extensions are used. In other words, Linux, Microsoft and DJGPP have some specific library functions that one or the other won't have.
It used to be a challenge getting programs to compile that didn't belong on the operating system. These days there is often a pre-compiled executable for Linux and Windows.
Shadow Wolf
Marc
2011-06-25 23:35:52 UTC
Not to be sarcastic, but you can use the actual c++ source on any platform that has a c++ editing program.
On the other hand, if you have already compiled and/or linked it using linux, you might not be able to execute it on windows.
The best option, not the only, is to get your source c++ and compile and link it on the windows computer so that it is "customized" for that environment.
The harder thing to do would be to de-assemble it. But, I think you can only do that with an assembly language.
?
2011-06-26 00:29:57 UTC
If you want to compile windows binaries on a linux computer, you'll need a cross-compiler. There are some good cross-compilers available for CodeBlocks. Otherwise you can run a windows-based compiler in Wine, such as Dev C++, to produce windows binaries.
the_dadd_from_tn2005
2011-06-25 23:41:56 UTC
You most certainly can. If you do use any Linux-specific components and the like, you can simply find Windows equivalents and port those portions of the code to Windows. Then you have a cross-platform application. :)
?
2011-06-25 23:33:02 UTC
For the most part. The C++ language itself is portable, as is the standard library, but if you use any Linux-specific libraries in your program, it won't work in Windows for obvious reasons.
ⓘ
This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.