Building Glibc in the Cygwin VM

  1. Add the following lines to C:\cygwin\usr\include\cygwin\stat.h (before the last #endif):
    #ifndef stat64
    #define stat64 stat
    #endif
    
  2. Update C:\Cygwin\opt\crosstool\src\build_cross_toolchain.sh :
    #!/bin/bash
    export TARGET=arm-linux-gnueabihf
    export PREFIX=/opt/crosstool/gcc-4.9.2-glibc-2.19/$TARGET
    export PATH=$PATH:$PREFIX/bin
    
    cd /opt/crosstool/src/build-glibc
    ../glibc-2.19/configure --prefix=/usr \
        --with-headers=$PREFIX/usr/include \
        --enable-add-ons=nptl --enable-kernel=4.0.0 \
        --with-binutils=$PREFIX --build=i686-pc-cygwin \
        --host=$TARGET --enable-shared --disable-profile \
        --with-tls --with-__thread --without-gd --without-cvs \
        --enable-add-ons \
        libc_cv_forced_unwind=yes libc_cv_c_cleanup=yes
    if [ "$?" -ne "0" ]; then
        echo "=== build script: failed to configure glibc ==="
        exit 1
    fi
    make
    if [ "$?" -ne "0" ]; then
        echo "=== build script: failed to make glibc ==="
        exit 1
    fi
    make install_root=$PREFIX install
    if [ "$?" -ne "0" ]; then
        echo "=== build script: failed to install glibc ==="
        exit 1
    fi
    
    echo "=== build script: OK ==="
    
  3. Run C:\Cygwin\opt\crosstool\src\build_cross_toolchain.cmd and wait until it completes.
  4. If there are no errors, shudown Cygwin VM and make snapshot "SNAP-9".
  5. Replace TARGET=arm-linux-gnueabihf with TARGET=arm-linux-gnueabi in C:\Cygwin\opt\crosstool\src\build_cross_toolchain.sh, then run C:\Cygwin\opt\crosstool\src\build_cross_toolchain.cmd and wait until it completes.
  6. If there are no errors, shudown Cygwin VM and make snapshot "SNAP-10".
  7. Undo stat64 preprocessor hack in C:\cygwin\usr\include\cygwin\stat.h.

Notes:

  • Glibc build will take a lot of time, 4-5 times more than binutils + gcc.
  • "--build=i686-pc-cygwin" configure option must be replaced with "--build=x86_64-pc-cygwin" if you have chosen 64-bit Cygwin.
  • libc_cv_forced_unwind=yes libc_cv_c_cleanup=yes options are here to disable linker tests. Because we run glibc build in the cross-environment, these tests create binary files which can't be executed and so fail the test.
  • "--enable-kernel" sets minimum version of Linux kernel for this glibc to run on. 4.0.0 should be good for Raspbian Jessie running on Raspberry Pi 3.
  • "--prefix=/usr" is not dangerous and will not hurt your /usr in host system, unless you call "make install" in plain and wrong way. This is an old glibc joke.
  • If you didn't apply glibc--cygwin-dirname-lookup.diff patch, you will get the following error during build:
    ../ports/sysdeps/arm/sysdeps/../nptl/pthread_spin_lock.c:23:47:
    error: #include nested too deeply
    #include <sysdeps/../nptl/pthread_spin_lock.c>
                                                   ^
    /opt/crosstool/src/build-glibc/sysd-rules:1857: recipe for target 
    `/opt/crosstool/src/build-glibc/nptl/pthread_spin_lock.o' failed
    make[2]: *** [/opt/crosstool/src/build-glibc/nptl/pthread_spin_lock.o] Error 1
    make[2]: Leaving directory `/opt/crosstool/src/glibc-2.19/nptl'
    Makefile:213: recipe for target `nptl/subdir_lib' failed
    make[1]: *** [nptl/subdir_lib] Error 2
    make[1]: Leaving directory `/opt/crosstool/src/glibc-2.19'
    Makefile:9: recipe for target `all' failed
    make: *** [all] Error 2
    
  • If you didn't apply glibc--cygwin-sunrpc-hdrs-libs.diff patch, you will get the following error during build:
    /opt/crosstool/src/build-glibc/sunrpc/cross-rpc_main.o:rpc_main.c:(.text+0x1f):
    undefined reference to `_libintl_setlocale'
    collect2: ld returned 1 exit status
    Makefile:169: recipe for target 
    `/opt/crosstool/src/build-glibc/sunrpc/cross-rpcgen' failed
    make[2]: *** [/opt/crosstool/src/build-glibc/sunrpc/cross-rpcgen] Error 1
    make[2]: Leaving directory `/opt/crosstool/src/glibc-2.19/sunrpc'
    Makefile:213: recipe for target `sunrpc/others' failed
    make[1]: *** [sunrpc/others] Error 2
    make[1]: Leaving directory `/opt/crosstool/src/glibc-2.19'
    Makefile:9: recipe for target `all' failed
    make: *** [all] Error 2
    

    or

    gcc rpc_parse.c -c -D_RPC_THREAD_SAFE_ -D_CROSS_RPCGEN_ \
    -o /opt/crosstool/src/build-glibc/sunrpc/cross-rpc_parse.o -MD -MP -MF /opt/crosstool
    /src/build-glibc/sunrpc/cross-rpc_parse.o.dt -MT /opt/crosstool/src/build-glibc/sunrpc/cross-rpc_parse.o
    In file included from rpc_parse.c:39:
    rpc/types.h:73: error: syntax error before "u_char"
    rpc/types.h:73: warning: useless keyword or type name in empty declaration
    rpc/types.h:73: warning: empty declaration
    rpc/types.h:74: error: syntax error before "u_short"
    rpc/types.h:74: warning: useless keyword or type name in empty declaration
    rpc/types.h:74: warning: empty declaration
    rpc/types.h:75: error: syntax error before "u_int"
    rpc/types.h:75: warning: useless keyword or type name in empty declaration
    rpc/types.h:75: warning: empty declaration
    rpc/types.h:76: error: syntax error before "u_long"
    rpc/types.h:76: warning: useless keyword or type name in empty declaration
    rpc/types.h:76: warning: empty declaration
    rpc/types.h:77: error: parse error before "quad_t"
    rpc/types.h:77: warning: data definition has no type or storage class
    rpc/types.h:78: error: parse error before "u_quad_t"
    rpc/types.h:78: warning: data definition has no type or storage class
    rpc/types.h:79: error: parse error before "fsid_t"
    rpc/types.h:79: warning: data definition has no type or storage class
    rpc/types.h:83: error: syntax error before "daddr_t"
    rpc/types.h:83: warning: useless keyword or type name in empty declaration
    rpc/types.h:83: warning: empty declaration
    rpc/types.h:84: error: syntax error before "caddr_t"
    rpc/types.h:84: warning: useless keyword or type name in empty declaration
    rpc/types.h:84: warning: empty declaration
    make[2]: *** [/opt/crosstool/src/build-glibc/sunrpc/cross-rpc_parse.o] Error 1
    make[2]: Leaving directory `/opt/crosstool/src/glibc-2.19/sunrpc'
    make[1]: *** [sunrpc/others] Error 2
    make[1]: Leaving directory `/opt/crosstool/src/glibc-2.19'
    make: *** [all] Error 2
     
     
  • If you didn't add stat64 preprocessor hack to C:\cygwin\usr\include\cygwin\stat.h as explained above, you will get the following error during build:
    rpc_main.c: In function `find_cpp':
    rpc_main.c:329:17: error: storage size of `buf' isn't known
    rpc_main.c: In function `checkfiles':
    rpc_main.c:1117:17: error: storage size of `buf' isn't known
    Makefile:165: recipe for target 
    `/opt/crosstool/src/build-glibc/sunrpc/cross-rpc_main.o' failed
    make[2]: *** [/opt/crosstool/src/build-glibc/sunrpc/cross-rpc_main.o] Error 1
    make[2]: Leaving directory `/opt/crosstool/src/glibc-2.19/sunrpc'
    Makefile:213: recipe for target `sunrpc/others' failed
    make[1]: *** [sunrpc/others] Error 2
    make[1]: Leaving directory `/opt/crosstool/src/glibc-2.19'
    Makefile:9: recipe for target `all' failed
    make: *** [all] Error 2
  • Also you may get error message about various missing syscalls (__-prefixed) if you forgot to replace .oS with .oZ in makefiles (Cygwin case-insensitive filesystem).


>> Read next section or buy already prepared cross-compiler ($10) to save your time.