Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix METIS compilation error on MinGW (gettimeofday issue) #490

Closed
wants to merge 1 commit into from

Conversation

Foadsf
Copy link
Contributor

@Foadsf Foadsf commented Jul 15, 2024

This commit resolves the compilation error in the METIS library when building Elmer FEM on Windows using MinGW. The error was caused by the use of the POSIX function gettimeofday, which is not directly available in Windows.

Changes made:

  1. Modified elmergrid/src/metis-5.1.0/GKlib/gk_arch.h to define gettimeofday as mingw_gettimeofday when compiling with MinGW.
  2. Updated elmergrid/src/metis-5.1.0/GKlib/timers.c to include gk_arch.h.

These changes allow the METIS library to compile successfully on Windows with MinGW, resolving the "implicit declaration of function 'gettimeofday'" error.

Fixes #489

This commit resolves the compilation error in the METIS library when building
Elmer FEM on Windows using MinGW. The error was caused by the use of the
POSIX function \`gettimeofday\`, which is not directly available in Windows.

Changes made:
1. Modified \`elmergrid/src/metis-5.1.0/GKlib/gk_arch.h\` to define
   \`gettimeofday\` as \`mingw_gettimeofday\` when compiling with MinGW.
2. Updated \`elmergrid/src/metis-5.1.0/GKlib/timers.c\` to include \`gk_arch.h\`.

These changes allow the METIS library to compile successfully on Windows
with MinGW, resolving the \"implicit declaration of function 'gettimeofday'\"
error.

Fixes #489
@mmuetzel
Copy link
Contributor

mmuetzel commented Jul 15, 2024

Thank you for looking into this and proposing a fix.

Adding #include <sys/time.h> in timers.c should be enough (and that would follow the include-what-you-use principle). It should be possible to do that without platform-specific guards. Matching how gettimeofday is used in this file, you could guard the header inclusion like the following:

#ifdef __GNUC__
#  include <sys/time.h>
#endif

I'm not sure if you should call mingw_gettimeofday in your code directly. No changes to gk_arch.h should be necessary.

@mmuetzel
Copy link
Contributor

As I noted in #489, this is likely not MinGW-specific. Instead, it is probably because the latest versions of GCC and LLVM default to C17 where implicit function declarations are an error. (These compilers emitted a warning in earlier versions for that.)

The issue should indeed be fixed by including sys/time.h as proposed in the previous comment.

@tzwinger tzwinger requested a review from raback July 15, 2024 19:45
@tzwinger
Copy link
Contributor

I added include of sys/time.h in timers.c - @Foadsf : can you please try if @mmuetzel 's hint worked

@tzwinger tzwinger removed the request for review from raback July 15, 2024 20:03
@Foadsf
Copy link
Contributor Author

Foadsf commented Jul 16, 2024

Dear @mmuetzel , Thanks for the kind support. Checking out the latest commits on the repo 77bbe42cd96e213af77e4e83453db905e2232f8f, the #489 is now resolved and can be closed. Any chance that I can also communicate with you via email? OR have you on the Discord channel?

Dear @tzwinger , please feel free to reject this PR.

@mmuetzel
Copy link
Contributor

@Foadsf: No worries.
I'm not sure what you are trying to discuss that others aren't allowed to read along. Writing here in issues or PRs is fine with me.
I'll also try to connect to the Discord channel from time to time.

@Foadsf
Copy link
Contributor Author

Foadsf commented Jul 16, 2024

@mmuetzel thanks for the response. It is not about secrecy 😅 but that there are others on Discord who, for whatever reason, do not use GitHub. Also to avoid bloating the discussions here on GitHub. 🖖

@tzwinger
Copy link
Contributor

OK, I then hereby close this PR, as it has been resolved with another code change

@tzwinger tzwinger closed this Jul 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Build Failure on Windows with MSYS2 MinGW due to gettimeofday and alloca Issues
3 participants