Problem 1721 - compile error: ::fsync doesn't exist on windows (MinGW)
Summary: compile error: ::fsync doesn't exist on windows (MinGW)
Status: RESOLVED FIXED
Alias: None
Product: Geant4
Classification: Unclassified
Component: analysis (show other problems)
Version: 10.0
Hardware: PC Windows
: P5 trivial
Assignee: Ivana.Hrivnacova
URL:
Depends on:
Blocks:
 
Reported: 2015-03-12 20:18 CET by Mojca Miklavec
Modified: 2015-04-09 14:55 CEST (History)
1 user (show)

See Also:


Attachments
A patch for MinGW compiler (322 bytes, application/octet-stream)
2015-03-12 20:18 CET, Mojca Miklavec
Details

Note You need to log in before you can comment on or make changes to this problem.
Description Mojca Miklavec 2015-03-12 20:18:07 CET
Created attachment 321 [details]
A patch for MinGW compiler

I would like to request a trivial patch to fix the compilation error with MinGW (even if the compiler is not officially supported):

--- a/source/analysis/g4tools/include/tools/wroot/file
+++ b/source/analysis/g4tools/include/tools/wroot/file
@@ -138,7 +138,7 @@ public: //ifile
 
   virtual bool synchronize(){
     // Synchornize a file's in-core and on-disk states.
-#ifdef WIN32
+#ifdef _WIN32
     return true;
 #else
     if (::fsync(m_file) < 0) {

Without the patch MinGW compiler enters the "else" part and breaks because ::fsync is not defined under windows.

(I didn't check any version of Geant4 other than 10.0 yet, but it would be nice to apply that for all supported and affected versions.)

Thank you.
Comment 1 Ivana.Hrivnacova 2015-03-16 18:16:13 CET
Hello,

Could you, please, test the following change, suggested by the author of this code,
and let us know if it fixes your problem as well?

Thank you,

  virtual bool synchronize(){
    // Synchornize a file's in-core and on-disk states.
#ifdef _MSC_VER
    if(::_commit(m_file)) {
      m_out << "inlib::wroot::file::synchronize :"
            << " in _commit() for file " << sout(m_path) << "."
            << std::endl;
      return false;
    }
#elif defined(__MINGW32__) || defined(__MINGW64__)
    return true;
#else
    if (::fsync(m_file) < 0) {
      m_out << "inlib::wroot::file::synchronize :"
            << " error in fsync() for file " << sout(m_path) << "."
            << std::endl;
      return false;
    } 
#endif
    return true;
  }
Comment 2 Mojca Miklavec 2015-03-16 18:42:04 CET
I need to get back to the windows machine where I have installation of Geant4 (it might take a few days), but I don't understand what exactly is it that you would like me to test.

From what I see the major change has been done in the MSVC section, while I was trying to make the MinGW compiler to work and my compiler would skip that part. (I have reached the point of successful compilation and installation, but not all the functionality works properly yet.) Or do you only want me to test if "#elif defined(__MINGW32__) || defined(__MINGW64__)" resolves to true for me (what about cygwin)?


In current code for Geant4, WIN32 is defined whenever MSVC is being used (by some Geant4 trickery). _WIN32 is defined for any compiler on windows. My blind guess is that "#ifdef _MSC_VER" currently has the same meaning as "#ifdef WIN32" inside Geant4 sources, but I should double-check that. A lot of Geant4 code makes no distinction between MSVC and Windows as an operating system (where MinGW or Cygwin can also be used), so I would expect more problems than just this one.


Anyway, it would be most helpful to get some additional instructions of what you want me to do.
Comment 3 Ivana.Hrivnacova 2015-03-16 22:09:56 CET
I am posting the reply from Guy Barrand, the g4tools developer:

Yes :
"all the functionality works properly yet.) Or do you only want me to test if
"#elif defined(__MINGW32__) || defined(__MINGW64__)" resolves to true for me
(what about cygwin)?"
testing that __MINGW32__ or __MINGW64__ are the right flags that signs the g++ compiler under MinGW is the thing to do.

No:
 WIN32 is not defined for all compilers on Windows, Dixit the web CYGWIN/g++ does not
define it by default, you have to add the -mwin32 option). (Which, that’s right, let the problem of testing “Windows as an operating system” not straightforwardly solved. Which for the moment I am going to continue to “ifdef” with WIN32 in my things).
Comment 4 Mojca Miklavec 2015-03-17 14:00:49 CET
A test on another machine with mingw-w64 and a simple hello-world example:

- 32-bit compiler has __MINGW32__ defined
- 64-bit compiler has both __MINGW32__ and __MINGW64__ defined

So there is no reason to check for both. Testing just for __MINGW32__ should do.

(What's weird though is that WIN32 was also defined here when running a simple hello-world example. WIN32 usually wasn't defined when I tried to compile Geant4 with MINGW, so I need to investigate a bit further.)
Comment 5 Ivana.Hrivnacova 2015-04-09 14:55:07 CEST
A fix provided by Guy Barrand (in g4tools 1.17.2 and 1.19.0) is now included in Geant4 development version and also schedule for the next path to 10.01 release.

Best regards,