Menu

#857 link error: undefined references to get_fmode, set_fmode

v1.0 (example)
open
nobody
None
5
2024-06-25
2020-09-28
Jannick
No

Version 8.0.0.6001.98dad1fe, used with MSYS2's MINGW64:

The functions set_fmode and get_mode are not provided in the libraries, whereas they are defined in the header files.

Test case:

/* t_fmode.c */
#include <stdlib.h>
#include <fcntl.h>

int main () {
  int fmode;
  _get_fmode (&fmode);
  _set_fmode(_O_BINARY);
  return 0;
}

While t_mode.c compiles well (i.e. gcc -c t_mode.c), the link command fails as the import symbols __imp__get_fmode and __imp__set_fmode cannot be resolved.

Error when running gcc t_fmode.c:

C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\msys64\tmp\cckT8P77.o:t_fmode.c:(.text+0x17): undefined reference to `__imp__get_fmode'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\msys64\tmp\cckT8P77.o:t_fmode.c:(.text+0x25): undefined reference to `__imp__set_fmode'

Happy to provide more information if needed.

Thanks.

Discussion

  • Jon Scobie

    Jon Scobie - 2020-10-20

    Same problem here.
    undefined reference to '__imp__set_fmode'

     
  • Orgad Shaneh

    Orgad Shaneh - 2024-05-21

    Looks like in MinGW you're supposed to use _fmode = _O_BINARY instead. See here for example.

     
  • Pali

    Pali - 2024-06-25

    Functions _get_fmode() and _set_fmode() are available in msvcrt.dll OS system library since Windows Vista.

    Commit 2924b5733903a imported all Windows Vista symbols into msvcrt.def.in mingw-w64 definition file.

    So the issue should be fixed now.

    Note that _fmode = _O_BINARY is preferred variant as it does not depends on Windows Vista libraries.

     

Log in to post a comment.