LinuxCommandLibrary

windres

Compile Windows resource scripts

SYNOPSIS

windres [options] [input-file] [output-file]

PARAMETERS

-i file, --input=file
    Specifies the input file. This can be a resource script (.rc) for compilation or a binary resource (.res) for decompilation.

-o file, --output=file
    Specifies the output file. This will typically be a binary resource (.res) when compiling or a resource script (.rc) when decompiling.

--input-format=format
    Sets the format of the input file. Common formats include rc (resource script), res (binary resource), and coff (COFF object file with resources).

--output-format=format
    Sets the desired format for the output file. Typical values are rc or res.

--target=bfdname
    Specifies the target BFD architecture for the output .res file. Examples include pe-i386 for 32-bit Windows or pe-x86-64 for 64-bit Windows.

-I dir, --include-dir=dir
    Adds dir to the list of directories that will be searched for included files during the preprocessing of resource scripts.

-D macro, --define=macro
    Defines a macro, which is passed to the preprocessor when compiling resource scripts, similar to -D in gcc.

-U macro, --undefine=macro
    Undefines a macro, passed to the preprocessor.

--preprocessor=program
    Specifies an external preprocessor program to use instead of the default one for resource script processing.

-l langid, --language=langid
    Sets the default language ID for resources that do not explicitly specify one.

-v, --verbose
    Enables verbose output, displaying more detailed information about the processing steps.

--help
    Displays a help message and exits.

--version
    Displays the version information and exits.

DESCRIPTION

windres is the GNU resource compiler, a key component of the GNU Binutils project. Its primary function is to process resource script (.rc) files, which define user interface elements and data for Windows applications, and compile them into binary resource (.res) files. Conversely, it can also decompile existing .res files or resources embedded within Portable Executable (PE) files (like .exe or .dll) back into human-readable .rc scripts.

This tool is indispensable for cross-development environments, particularly for developers on Unix-like operating systems (such as Linux or macOS) who need to build applications for Microsoft Windows targets using toolchains like MinGW-w64. It enables these applications to incorporate native Windows elements such as icons, cursors, menus, dialog boxes, string tables, and version information, ensuring a consistent and complete Windows user experience.

CAVEATS

windres is specifically designed for handling resources for Microsoft Windows PE (Portable Executable) files and is not intended for managing native Linux resources. When used to build Windows applications on Linux, it requires a correctly configured cross-compilation toolchain, such as MinGW-w64. The syntax of Windows resource script (.rc) files can be intricate, and while windres aims for compatibility with Microsoft's RC.exe, subtle differences or complex resource definitions might occasionally lead to unexpected behavior.

RESOURCE SCRIPT (<CODE>.RC</CODE>) FILES

These are plain text files that define the resources to be embedded within a Windows application. They can specify various elements like icons, cursors, bitmaps, menus, dialog boxes, string tables, version information, and even custom binary data. windres reads and preprocesses these files to generate the binary resource output.

BINARY RESOURCE (<CODE>.RES</CODE>) FILES

After compilation by windres, the output is typically a .res file. This binary file contains the compiled resources in a format suitable for linking. It is then combined with compiled object files (.obj) by a linker (like ld) to form a complete Windows Portable Executable (PE) file, such as an .exe or .dll.

INTEGRATION WITH MINGW-W64

In a typical cross-compilation workflow on Linux for Windows, windres is often invoked as part of the MinGW-w64 toolchain. The specific command might be prefixed to target the correct architecture, for example, x86_64-w64-mingw32-windres, ensuring that the compiled resources are compatible with the intended Windows architecture (e.g., 64-bit Windows).

HISTORY

windres is an integral component of the GNU Binutils project, a comprehensive collection of programming tools. Its development was driven by the necessity to provide a free and open-source alternative to Microsoft's proprietary Resource Compiler (RC.exe). This tool was crucial for advancing cross-compilation efforts, enabling developers on Unix-like operating systems to build fully functional applications for Windows targets. Its continued evolution supports projects like MinGW (Minimalist GNU for Windows) and Wine, allowing the seamless integration of native Windows resources (such as icons, dialogs, and version information) into executables and libraries compiled in non-Windows environments.

SEE ALSO

gcc(1), ld(1), ar(1), objdump(1), make(1)

Copied to clipboard