2

I have a Linux C++ application which run as a daemon. When user executes this application, it will be running in the background, listening on a port, and waiting for connection from the clients.

Is it possible to port this kind of application to Windows platform using Cygwin or MinGW?

Thanks.

user010203
  • 73
  • 1
  • 3

2 Answers2

2

It is possible to port almost anything (unless it makes sense only to one OS). The question is, "how hard is it to port application X"? And to help answer that question, we need to see source code.

General purpose tips

It basically boils down to how much compiler/system-dependent code you've spread out over your code base. I see you're using at least two things that are sensitive: daemons and sockets.

Daemons are tricky to port as the equivalent on Windows (a windows service) requires different platform-specific code. This is fixed cost (e.g. does not vary on the size of the rest of the application).

Sockets are more or less tricky to port depending on whether you're using advanced networking features (asynchronous I/O, etc.), which tend to vary more from system to system. It also depends on whether you abstracted socket manipulation code into some re-usable component. Windows supports a very similar sockets interface (the classic BSD socket interface with minor modifications to random parts of the API). Changing one Socket class is easier than changing your code if you didn't write a wrapper class.

André Caron
  • 44,541
  • 12
  • 67
  • 125
2

Cygwin aims at POSIX/Linux source level compatibility, so your application is supposed to build and work there with no or only minor modifications.

MinGW does not try to provide such a compatibility layer. It's just the GNU toolchain for Windows, so you would need to replace any uses of POSIX/Linux-specific APIs with Windows equivalents.

ak2
  • 6,629
  • 31
  • 27
  • 1
    +1 In particular, Cygwin implements `fork` in a (functionally) exactly identical way, which is one of the things you need for daemonizing a process. Though admittedly, I'd personally prefer writing a native implementation (i.e. service) even if it's more work. – Damon Oct 21 '11 at 17:08