Evironment

Mount image

mount root file system to /mnt

$ unzip 2017-11-29-raspbian-stretch.zip 
Archive:  2017-11-29-raspbian-stretch.zip
  inflating: 2017-11-29-raspbian-stretch.img

$ sudo fdisk -l 2017-11-29-raspbian-stretch.img 
[sudo] password for wind: 

Disk 2017-11-29-raspbian-stretch.img: 4919 MB, 4919918592 bytes
255 heads, 63 sectors/track, 598 cylinders, total 9609216 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x49783f5b

                          Device Boot      Start         End      Blocks   Id  System
2017-11-29-raspbian-stretch.img1            8192       93236       42522+   c  W95 FAT32 (LBA)
2017-11-29-raspbian-stretch.img2           94208     9609215     4757504   83  Linux

### offset = 94208 * 512 = 48234496
$ sudo mount -o loop,offset=48234496 2017-11-29-raspbian-stretch.img /mnt
$ cd /mnt
ROOTFS=/mnt
TOOLCHAIN=/path/to/gcc-linaro-4.9-2015.02-3-x86_64_arm-linux-gnueabihf/bin/arm-linux-gnueabihf-

Configure

$ tar -xJvf qt-everywhere-src-5.10.0.tar.xz 
$ cd qt-everywhere-src-5.10.0
$ ./configure -opengl es2 -device linux-rasp-pi3-g++ -device-option CROSS_COMPILE=/home/wind/opt/raspi/tools/arm-bcm2708/gcc-linaro-4.9-2015.02-3-x86_64_arm-linux-gnueabihf/bin/arm-linux-gnueabihf- -sysroot /mnt -opensource -confirm-license -optimized-qmake -reduce-exports -release -make libs -prefix /usr/local/qt5
### add -make tools -make examples options if need

ERROR like these

ERROR: Cannot compile a minimal program. The toolchain or QMakeSpec is broken.
ERROR: The OpenGL functionality tests failed! You might need to modify the include and library search paths 
by editing QMAKE_INCDIR_OPENGL[_ES2], QMAKE_LIBDIR_OPENGL[_ES2] and QMAKE_LIBS_OPENGL[_ES2] in the mkspec for your platform.

To fix these errors, modify device mkspec file linux-rasp-pi3-g++/qmake.conf like this

VC_LIBRARY_PATH         = $$[QT_SYSROOT]/opt/vc/lib
VC_INCLUDE_PATH         = $$[QT_SYSROOT]/opt/vc/include

QMAKE_LIBDIR_OPENGL_ES2 = $${VC_LIBRARY_PATH}
QMAKE_LIBDIR_EGL        = $$QMAKE_LIBDIR_OPENGL_ES2
QMAKE_LIBDIR_OPENVG     = $$QMAKE_LIBDIR_OPENGL_ES2

QMAKE_INCDIR_EGL        = \
                        $${VC_INCLUDE_PATH} \
                        $${VC_INCLUDE_PATH}/interface/vcos/pthreads \
                        $${VC_INCLUDE_PATH}/interface/vmcs_host/linux
QMAKE_INCDIR_OPENGL_ES2 = $${QMAKE_INCDIR_EGL}
QMAKE_INCDIR_OPENVG     = $${QMAKE_INCDIR_EGL}

QMAKE_LIBS_OPENGL_ES2   = -lGLESv2
QMAKE_LIBS_EGL          = -lEGL -lGLESv2
QMAKE_LIBS_OPENVG       = -lEGL -lOpenVG -lGLESv2

When all error fixed, configure will create qmake, output like this means configure ok

+ cd qtbase
### ..............
Creating qmake...
........................................
.Done.

This is the Qt Open Source Edition.

You have already accepted the terms of the Open Source license.

Running configuration tests...
Done running configuration tests.

Configure summary:

Building on: linux-g++ (x86_64, CPU features: mmx sse sse2)
Building for: devices/linux-rasp-pi3-g++ (arm, CPU features: neon)
Configuration: cross_compile compile_examples enable_new_dtags largefile neon precompile_header shared rpath release c++11 c++14 concurrent dbus reduce_exports release_tools stl
Build options:
  Mode ................................... release; optimized tools
  Optimize release build for size ........ no
  Building shared libraries .............. yes
  Using C++ standard ..................... C++14
  Using ccache ........................... no
  Using gold linker ...................... no
  Using new DTAGS ........................ yes
  Using precompiled headers .............. yes
  Using LTCG ............................. no
  Target compiler supports:
    NEON ................................. yes
  Build parts ............................ libs

### ..................

Note: Also available for Linux: linux-clang linux-icc

Note: -optimized-tools is not useful in -release mode.

Note: No wayland-egl support detected. Cross-toolkit compatibility disabled.

Qt is now configured for building. Just run 'make'.
Once everything is built, you must run 'make install'.
Qt will be installed into '/mnt/usr/local/qt5'.

Prior to reconfiguration, make sure you remove any leftovers from
the previous build.

Make

$ make
### or
$ make -j4

Compile ERROR fix

error: cannot open /mnt/usr/lib/arm-linux-gnueabihf/libz.so: No such file or directory

### and libm.so, librt.so, libdl.so

undefined reference to `__dlsym'

make *** [sub-src-make_first] Error 2

arm-linux-gnueabihf/bin/ld: cannot find -lm
### and -lc

Reason:
in root file system, some libs are symlinks, but they are absolute path, when run raspberry pi that is ok, but in host, symlinks cannot find correctly libraries, so we need fix this use related path relink symlinks

$ cd /mnt/usr/lib/arm-linux-gnueabihf/
$ sudo rm libdl.so 
$ sudo ln -s ../../../lib/arm-linux-gnueabihf/libdl.so.2 libdl.so
$ sudo rm libz.so 
$ sudo ln -s ../../../lib/arm-linux-gnueabihf/libz.so.1 libz.so
$ sudo rm libutil.so 
$ sudo ln -s ../../../lib/arm-linux-gnueabihf/libutil.so.1 libutil.so
$ sudo rm librt.so
$ sudo ln -s ../../../lib/arm-linux-gnueabihf/librt.so.1 librt.so
$ sudo rm libm.so 
$ sudo ln -s ../../../lib/arm-linux-gnueabihf/libm.so.6 libm.so

### maybe we need same symlinks in /lib/arm-linux-gnueabihf/ too

$ cd /mnt/lib/arm-linux-gnueabihf/
$ sudo ln -s libz.so.1 libz.so
$ sudo ln -s libdl.so.2 libdl.so
$ sudo ln -s librt.so.1 librt.so
$ sudo ln -s libm.so.6 libm.so

### and in some system image EGL, GLESv2, OpenVG libraries were renamed

$ cd /mnt/opt/vc/lib
$ sudo ln -s libbrcmEGL.so libEGL.so
$ sudo ln -s libbrcmGLESv2.so libGLESv2.so
$ sudo ln -s libbrcmOpenVG.so libOpenVG.so
$ sudo ln -s libbrcmWFC.so libWFC.so

Now we can compile Qt libs/tools/examples succesfully, and install

$ sudo make install

### all files will be install to '/mnt/usr/local/qt5'

Then, sudo umount /mnt and write new image file to SD card, boot raspberry pi3, run an example.

Write image to SD card

Plugin sdcard and umount partitions, write image file us dd command

$ sudo umount /dev/sdd1
$ sudo umount /dev/sdd2
$ sudo dd bs=4M if=2017-11-29-raspbian-stretch.img of=/dev/sdd
### NOTE: there is no `sdd1` or `sdd2`

Boot raspberry pi3, if want to use qmake on pi3, run

$ sudo apt-get update
$ sudo apt-get install qt5-qmake qt5-default

References