views:

101

answers:

4

I need to write a relatively simple command line C++ program to be run a Linux environment. However, I would like to code as well as compile this on Windows. The reason I don't want to port it to Linux is because it requires MySQL interactions, and that would require some messy porting (IMO). It does not have to run on Windows; I just want to compile it on Windows because I want to use my preferred IDE's.

I've looked up on Cygwin for this task, but I haven't been able to find any documentation to do what I'm trying to do.

+1  A: 

MinGW + MSYS

MinGW provides the functionality, MSYS gives a linux-like command prompt to use MinGW at.

Graphics Noob
A: 

Install cygwin (tutorial) and you'll have an EXE that gives you the command line prompt you're looking for.

The Cygwin installer should have an option for installing whatever compiler you're looking for (gcc?).

Here's another relevant tutorial.

Dolph
+1  A: 

When you get cygwin, install the C++ compiler/build tools, e.g., gcc, g++, make, autotools, etc. I think these are all you need, but I may be wrong. In any case the Cygwin installer is easy to use, and should bring in any dependencies.

Once you have these setup, you can configure your IDE to use g++ as your default compiler. You also need to set your library and include paths correctly such that they point to the relative /usr/include and /usr/lib directories under $CYGWIN (%CYGWIN%).

(Your other option is to use MinGW set of tools, in which case the IDE setup is more or less the same.)

0xfe
+1  A: 

(I'm assuming "..don't want to port it to Linux.." is a typo for "..from Linux" and that you want the code to run in Linux as you said in your first sentence. This means cygwin or mingw would only be used as cross compilers and aren't going to be very useful.)

This program already builds and works (or mostly works) on Linux, right? No reason to change that. Use your preferred editor (probably the one in your IDE) to edit the files and then just run the build system (probably make) in a Linux system (possibly in a VM). Export the files using a samba share (especially easy from a VM) so you can edit and automatically save remotely.

Note that you seem fine ditching every other feature of your IDE (debugger and compiler, mainly) and just using the editor part anyway.


Ah, are you not starting from any existing project and want to write this from scratch? If so, porting doesn't make any sense. You want to write cross-platform code. (Cross-platform or "portable code" being related to, but different than, the act of "porting code" from one platform to another.)

The code is then both "Windows code" and "Linux code" at the same time, and you can use any compiler on Windows that can accept the code. Usually this happens by you sticking to standard libraries and other portable libraries, or writing shims for non-portable libraries to give them a portable interface, with the compiler supporting the C++ Standard.

You can use your preferred IDE's compiler and debugger in this case, and don't need cygwin or mingw. (Unless they're used by your preferred IDE. :P)

Roger Pate