Cross compile application built with MS Visual studio 2010
I have written a code, basically for windows using VC++ with development environment MS Visual Studio 2010.
Note: it is console- application and does not contain GUI. So I would like to cross- compile.
I want my code 开发者_如何学运维to compile to Linux as well without modifying the code. I mean, I Wish to do cross-compile. Can anyone please describe me briefly on "how-to" or re-direct me to few posts on StackOverflow.
While you can I'm sure dig up a linux-targeted version of GCC cross compiled to run under windows (or build it from sources using a version of GCC which targets the windows platform, such and MINGW's or cygwin's) it may prove easier to install a smaller linux distribution, perhaps a console-only one, in a virtual machine.
As you mentioned, you have done I/O using the WIN32 API. You will need to change this to unix/posix type methods, probably including learning about changing the terminal settings, which can be a bit of a learning experience. To know that you got this right, you'll need to be able to test it. Building the "linux" version of your code under cygwin and running it on your windows box might work, but it's probably best to gain some familiarity with the actual target operating system.
Just verifying that your windows executable runs under Wine which Dani mentioned wouldn't be a bad idea either. There's also a library, Winelib, that aims to help with porting by providing substitutes for the windows calls when trying to compile your code for linux.
Finally, just switching compilers from MSVC to GCC, regardless if you target linux or windows or cygwin, is probably going to require some changes to your source code. MSVC will tolerate a number of dodgy things that GCC won't, for example in how you declare structs. The reverse is probably also true. But with some learning and regularly feeding your project to both compilers, you can maintain portable code.
Just make sure your using ANSI version of c++ (no clr staff ect.) and it should compile on linux as well.
you might want to look for a tool that converts csproj into makefiles, or write them yourself.
精彩评论