nabijaczleweli / rust-embed-resource

A Cargo build script library to handle compilation and inclusion of Windows resources, in the most resilient fashion imaginable
MIT License
166 stars 29 forks source link

Linking fails on target i686-pc-windows-gnu because of unrecognized output object file format #34

Closed utoalex closed 3 years ago

utoalex commented 3 years ago

Trying to compile anything depending on a resource (.rc) file using on an amd64 computer using target i686-pc-windows-gnu yields the following error:

linking with `i686-w64-mingw32-gcc` failed: exit code: 1
  |
  = note: "i686-w64-mingw32-gcc" <lots of args...>
  = note: <project root>\target\debug\build\<project name>-<hash>\out/libresources.a: file not recognized: File format not recognized 

This error seems to stem from an incorrect use of mingw-w64's windres.exe resource compiler (just in this case), in windows_not_msvc.rs.

By default,mingw-w64's windres.exe compiles the input resource file into an amd64 object file format (at least when running on an amd64 computer), which is incompatible with i686 targets, thereby causing linking to fail. A fix for this would consist in detecting that i686 machines are being targeted (using cfg!(target_arch = "x86_64")), and using flag --target=pe-i386 just after -O coff/--output-format=coff, like this:

windres --output-format=coff --target=pe-i386 <resource file>

As a temporary workaround, using the above command line manually to compile the resource file and replacing the invalid libresources.a resource file generated by this crate with our manually compiled file fixes builds broken by this issue.

nabijaczleweli commented 3 years ago

Can you try with the current master branch (at least 7d2c55110df9d3e387015bbc22cec6e59a2aa2c7)?

utoalex commented 3 years ago

Just tried it and it works fine now, thanks!

nabijaczleweli commented 3 years ago

Hog. Released in v1.6.2, thanks for the draft of the fix!