-
Notifications
You must be signed in to change notification settings - Fork 34
Description
Many code bases tend to capitalize various letters in the Windows headers when they include them. That is fine when compiling on Windows systems, since that file system is case-insensitive and the compiler doesn't care about the capital letters. When using mingw to cross-compile on Linux systems though, the header must be all lowercase, so these codes fail to build because they have capital letters. e.g., they do #include "Windows.h"
, but mingw only has windows.h
, so it fails to build.
GCC and Clang both support a command option to remap headers (originally to deal with DOS path length restrictions: -remap
. This option is described as:
When searching for a header file in a directory, remap file names if a file named
header.gcc' exists in that directory. This can be used to work around limitations of file systems with file name restrictions. The
header.gcc' file should contain a series of lines with two tokens on each line: the first token is the name to map, and the second token is the actual name to use.
We should automatically generate a header.gcc
file in the mingw sysroot to map the most common capital headers into their lowercase equivalent (e.g., at least map Windows.h
into windows.h
.), and also automatically pass the -remap
option into the toolchain via the toolchain files.
A sample piece of script that can do this in a build recipe is:
C_FLAGS=()
# Tell the compiler to actually use the lowercased header file
if [[ "${target}" == *-mingw32* ]]; then
echo "Windows.h windows.h" >> /opt/${target}/${target}/sys-root/include/header.gcc
C_FLAGS+=(-remap)
fi