Menu

#473 undefined reference to `_mkgmtime' using i686-w64-mingw32-gcc

v1.0 (example)
open
nobody
None
5
2021-03-21
2015-04-07
No

Dear MinGW-w64 developers,

I'm trying to compile an application with MinGW as packaged with Cygwin:

mingw64-i686-gcc 4.8.3-1
mingw64-i686-binutils 2.24.0.3.85cf705-1
mingw64-i686-headers 3.3.0-1
mingw64-i686-runtime 3.3.0-1

The following simple test case:

#include <time.h>

int main()
{
    struct tm tm;
    _mkgmtime(&tm);
}

fails to compile with the following error:

$ i686-w64-mingw32-gcc -o test.exe test.c 
/tmp/ccOjOHdH.o:test.c:(.text+0x16): undefined reference to `_mkgmtime'
collect2: error: ld returned 1 exit status

As far as I can tell, I'm including the correct headers. I also tried the first sample application at https://msdn.microsoft.com/en-us/library/2093ets1.aspx, and it fails to link with the same error.

Interestingly, the 64-bit version of this compiler (x86_64-w64-mingw32-gcc) appears to work fine! I suspect there is a problem with the aliasing of symbols in time.h. I can see that there are inline redirections to _mkgmtime32/_mkgmtime64 which are only active if __CRT__NO_INLINE is not defined, but I can't figure out how to get it undefined. Compiling with -finline makes no difference to the error messages.

Thanks in advance for your help!

Cheers, Chris.

Related

Bugs: #473

Discussion

  • qbt937

    qbt937 - 2015-04-19

    I have reproduced this bug on my machine, and I saw that _mkgmtime was in msvcrt on 64 bit, but not on 32 bit. msvcrt is a library that contains the C-runtime and it is linked automatically. Because of this I looked at the mingw-w64 source, and saw that mingw-w64-crt/lib64/msvcrt.def.in contains _mkgmtime, but mingw-w64-crt/lib32/msvcrt.def.in does not. This makes me think that if you add _mkgmtime and _mkgmtime32 to mingw-w64-crt/lib32/msvcrt.def.in and rebuild mingw-w64 it will fix your problem, but I haven't been able to test this.

     
  • Chris Wilson

    Chris Wilson - 2015-05-15

    Yes, that change does fix the link error, thanks!

     
  • jeroen

    jeroen - 2018-07-07

    This is still not working in v5.0.4. Could we simply add the symbol as suggested above? That would be really helpful.

     
  • Jay Satiro

    Jay Satiro - 2021-03-21

    I also had this problem using the packaged version in Ubuntu 16 LTS. mkgmtime is missing from libmsvcrt.a. I think it is fixed in later versions because I tried in Windows in msys2 using mingw-w64 i686 and it worked fine.

    owner@ubuntu1604-x64-vm:/usr/x86_64-w64-mingw32/lib$ grep mkgmtime *
    grep: ldscripts: Is a directory
    Binary file libcrtdll.a matches
    Binary file libmsvcr100.a matches
    Binary file libmsvcr110.a matches
    Binary file libmsvcr80.a matches
    Binary file libmsvcr90.a matches
    Binary file libmsvcr90d.a matches
    Binary file libmsvcrt.a matches
    
    owner@ubuntu1604-x64-vm:/usr/i686-w64-mingw32/lib$ grep mkgmtime *
    grep: ldscripts: Is a directory
    Binary file libcrtdll.a matches
    Binary file libmsvcr100.a matches
    Binary file libmsvcr110.a matches
    Binary file libmsvcr80.a matches
    Binary file libmsvcr90.a matches
    Binary file libmsvcr90d.a matches
    
     
    • jeroen

      jeroen - 2021-03-22

      This was fixed in mingw-w64 v6. The fix was also back-ported to v5 but this
      branch was never re-released:
      https://github.com/mingw-w64/mingw-w64/commit/3b43430a378c357fcf67564d0dfd34aa1db68b48

      On Mon, Mar 22, 2021 at 12:12 AM Jay Satiro raysatiro@users.sourceforge.net
      wrote:

      I also had this problem using the packaged version in Ubuntu 16 LTS.
      mkgmtime is missing from libmsvcrt.a. I think it is fixed in later versions
      because I tried in Windows in msys2 using mingw-w64 i686 and it worked fine.

      ~~~
      owner@ubuntu1604-x64-vm:/usr/x86_64-w64-mingw32/lib$ grep mkgmtime *
      grep: ldscripts: Is a directory
      Binary file libcrtdll.a matches
      Binary file libmsvcr100.a matches
      Binary file libmsvcr110.a matches
      Binary file libmsvcr80.a matches
      Binary file libmsvcr90.a matches
      Binary file libmsvcr90d.a matches
      Binary file libmsvcrt.a matches

      owner@ubuntu1604-x64-vm:/usr/i686-w64-mingw32/lib$ grep mkgmtime *
      grep: ldscripts: Is a directory
      Binary file libcrtdll.a matches
      Binary file libmsvcr100.a matches
      Binary file libmsvcr110.a matches
      Binary file libmsvcr80.a matches
      Binary file libmsvcr90.a matches
      Binary file libmsvcr90d.a matches
      ~~~


      [bugs:#473] undefined reference to `_mkgmtime' using
      i686-w64-mingw32-gcc

      Status: open
      Group: v1.0 (example)
      Created: Tue Apr 07, 2015 10:57 PM UTC by Chris Wilson
      Last Updated: Sat Jul 07, 2018 09:04 AM UTC
      Owner: nobody

      Dear MinGW-w64 developers,

      I'm trying to compile an application with MinGW as packaged with Cygwin:

      mingw64-i686-gcc 4.8.3-1
      mingw64-i686-binutils 2.24.0.3.85cf705-1
      mingw64-i686-headers 3.3.0-1
      mingw64-i686-runtime 3.3.0-1

      The following simple test case:

      #include <time.h>
      
      int main()
      {
          struct tm tm;
          _mkgmtime(&tm);
      }
      

      fails to compile with the following error:

      $ i686-w64-mingw32-gcc -o test.exe test.c
      /tmp/ccOjOHdH.o:test.c:(.text+0x16): undefined reference to `_mkgmtime'
      collect2: error: ld returned 1 exit status
      

      As far as I can tell, I'm including the correct headers. I also tried the
      first sample application at
      https://msdn.microsoft.com/en-us/library/2093ets1.aspx, and it fails to
      link with the same error.

      Interestingly, the 64-bit version of this compiler
      (x86_64-w64-mingw32-gcc) appears to work fine! I suspect there is a
      problem with the aliasing of symbols in time.h. I can see that there are
      inline redirections to _mkgmtime32/_mkgmtime64 which are only active if
      __CRT__NO_INLINE is not defined, but I can't figure out how to get it
      undefined. Compiling with -finline makes no difference to the error
      messages.

      Thanks in advance for your help!

      Cheers, Chris.


      Sent from sourceforge.net because you indicated interest in <
      https://sourceforge.net/p/mingw-w64/bugs/473/>

      To unsubscribe from further messages, please visit <
      https://sourceforge.net/auth/subscriptions/>

       

      Related

      Bugs: #473


Log in to post a comment.