I’m trying to compile a Windows DLL for code originally intended for a Unix platform. One problem I have is that Windows fopen()
defaults to O_TEXT
, but Unix defaults to O_BINARY
.
Windows recommends two ways to solve this:
- Use
_set_fmode()
function, didn’t work for me probably because I could not call it from correct context. - Link with
binmode.obj
object file. This file is included with the compiler, and the compiler knows where to look for it.
The latter worked for my own code, but it does not seem to work for third party static libraries. Looking at the linker output, I can see that static libraries are included before binmode.obj
, but binmode.obj
was included before my own object files.
The real solution should be to persuade all external libraries to include binmode.obj
, but this is somewhat non-trivial and might incur significant maintenance overhead in the future.
So I’d like to try to move the binmode.obj
to the beginning of the linker command line, but this proved to be surprisingly difficult. I’ve tried:
-
target_link_libraries( mylib PRIVATE binmode.obj )
- Got correct position, but got renamed tobinmode.obj.lib
. - Tried making a static library with
binmode.obj
as a pre-compiled object, but got an error that the file has a relative path. I have no idea how to make it a full path. - Tried adding it as a linker flag in different ways, even including using toolchain file, but it all ended up with
binmode.obj
being placed after libraries.
I’m now out of ideas and feel I need help with this. Any suggestions how to fix this?