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.
Same problem here.
undefined reference to '__imp__set_fmode'
Looks like in MinGW you're supposed to use
_fmode = _O_BINARY
instead. See here for example.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.