Search code examples
c++linuxwindowsinotify

Use inotify with MinGW


Is it possible to use inotify compiling on Windows with mingw? Because I would monitor change a file that is on a Linux server, but the program will be compiled and run on Windows7 machines. I think I have to use inotify and not Win32 API FindFirstChangeNotification. Is it possible to monitor a Linux directory from a Windows machine?

My error when I compile :

Microsoft Windows [Version 6.1.7601]
Copyright (c) 2009 Microsoft Corporation.  All rights reserved.

C:\Users\simon\Desktop>g++ main.c -o main.exe
main.c:5:25: fatal error: sys/inotify.h: No such file or directory
      #include <sys/inotify.h>
                     ^
compilation terminated.

Solution

  • No, inotify is a feature provided by Linux kernel, so in order to use it, program has to be run on Linux. Programs running on Windows have to use Windows APIs.

    If your application runs on Windows and has access to files on Linux servers, it still does it using Windows APIs, and Linux filesystem is exposed via some network filesystem (most probably SMB or NFS), that does the job of translating APIs and sending bytes via network.

    To conclude, if you want to monitor changes on remote system, first make sure your network filesystem supports change notifications, then use "local" APIs - in your case, Windows ones.