1

Background: I'm working on porting a large project that was developed in C++ exclusively for unix systems, to be compatible with windows to make way for an eventual windows distribution. I don't have very much experience in Windows development, but I'd like to get whatever I can do, done right, before senior developers move in and take over.

Question: So for a while, I've been looking up Windows versions for all the unix/posix calls that are used in the software, most coming from dirent.h, unistd.h, and some ones under sys, like sys/stat.h or sys/types.h. And although it'll take a lot of work to modify the programs to adopt the new Win32 API calling conventions and return types (and sometimes all new functions), it'll probably work, eventually.

But I've been seeing this come up frequently, the fact that MinGW, I guess, includes many native unix calls and functionalities as part of the GCC environment, and can translate them into windows-compatible calls so you can compile on Windows, and use said compiled program on Windows easily. In fact, one of the similar questions I read in the sidebar talks about just that. What I don't understand, and seem to have trouble understanding, is exactly the extent of this built-in translation functionality, and where I can find a list of system stuff that'll work with this.

Sorry this post is a little unstructured and that I'm so green with this, but I only have 2 weeks to try to accomplish something with this before I get swapped with a senior developer.

codechao
  • 67
  • 9

1 Answers1

4

No. MinGW does not attempt to implement UNIX functions on Windows. It cannot replicate most system calls with no effort.

However, Cygwin does do that.

user253751
  • 57,427
  • 7
  • 48
  • 90
  • Note, however, that Cygwin is a bandaid-and-sticky-tape solution. It works, most of the time, but it isn't elegant. (It is also incompatible with a [disturbingly long list of third-party applications](https://www.cygwin.com/faq.html#faq.using.bloda).) – Harry Johnston Aug 09 '16 at 04:47
  • @HarryJohnston That's because there is no elegant way to replicate Unix under Win32. (WSL is not under Win32) – user253751 Aug 09 '16 at 05:11
  • Yes, but it seems that the OP may have the option of actually porting the code. I just wanted to make sure they were aware of the downside to the seemingly easier solution. – Harry Johnston Aug 09 '16 at 05:22
  • (Virtualization would allow for a better approach IMO. But of course Cygwin doesn't use that approach for historical reasons, and I'm not sure there's enough demand for a brand new solution.) – Harry Johnston Aug 09 '16 at 05:26
  • This is for code that'll be sold to people, so less error prone solutions take priority over ease to port. This is also completely company-owned code, so I can make any changes to the source I want. Anyway, would people suggest just sticking to what I was doing and manually porting the calls "by hand"? Also, so what are people talking about when they say that MinGW can port things like the dirent.h group of system calls, or the _S_ISDIR macros? – codechao Aug 09 '16 at 06:05
  • I don't know, but according to [this answer](http://stackoverflow.com/a/20421614/886887) `dirent.h` can be implemented on Windows in a very lightweight way. Perhaps MinGW ships with such an implementation nowadays? – Harry Johnston Aug 09 '16 at 21:40
  • It looks like it does. And it does seem to come with implementations of many unix functions like stat, that work on windows. I'm not sure why the answer poster said that it doesn't unless I'm misunderstanding. – codechao Aug 10 '16 at 18:15