'get_osfhandle': identifier not found
-
I've found in a C function, from a Linux library a function: get_osfhandle:
handle = get_osfhandle(fd);
And it is declared up in the C file like this:
HANDLE get_osfhandle(int); /* from msvcrt.dll */
but I got a link error:
error LNK2019: unresolved external symbol "void * __cdecl get_osfhandle(int)" (?get_osfhandle@@YAPAXH@Z) referenced in function ...
I commented that line,
HANDLE get_osfhandle(int);
, and without this declaration, I got the error from post subject. Of course, I have included io.h header, like msdn said: _get_osfhandle | Microsoft Docs[^] But I got the same errors. I have tried to include , seem to be useless ... how to overcome this error ? -
I've found in a C function, from a Linux library a function: get_osfhandle:
handle = get_osfhandle(fd);
And it is declared up in the C file like this:
HANDLE get_osfhandle(int); /* from msvcrt.dll */
but I got a link error:
error LNK2019: unresolved external symbol "void * __cdecl get_osfhandle(int)" (?get_osfhandle@@YAPAXH@Z) referenced in function ...
I commented that line,
HANDLE get_osfhandle(int);
, and without this declaration, I got the error from post subject. Of course, I have included io.h header, like msdn said: _get_osfhandle | Microsoft Docs[^] But I got the same errors. I have tried to include , seem to be useless ... how to overcome this error ? -
Microsoft have helpfully changed the name, it is now
_get_osfhandle
(with a leading underscore), as defined in io.h.There are very clear and compelling reasons they had to do it when they embedded linux in the windows API via WSL2. Windows then effectively has both the linux and windows functions available and it needs to know which you are wanting to call which is down to what app you are compiling a linux one or a windows one. Compatibility | Microsoft Docs[^] If you aren't aware of WSL2 in Windows 10 it's time to meet to meet it :-) Trying the New WSL 2. It's Fast! (Windows Subsystem for Linux) ― Scotch.io[^]
In vino veritas
-
There are very clear and compelling reasons they had to do it when they embedded linux in the windows API via WSL2. Windows then effectively has both the linux and windows functions available and it needs to know which you are wanting to call which is down to what app you are compiling a linux one or a windows one. Compatibility | Microsoft Docs[^] If you aren't aware of WSL2 in Windows 10 it's time to meet to meet it :-) Trying the New WSL 2. It's Fast! (Windows Subsystem for Linux) ― Scotch.io[^]
In vino veritas