qt cross compilation for raspberry pi: Cannot find GLESv2

一个人想着一个人 提交于 2019-12-04 09:47:53

问题


I am trying to compile qt 5.9 for my raspberry pi 3 compute module and I have been following mainly the online guide here (https://wiki.qt.io/RaspberryPi2EGLFS). So, I have set the pi system roots to the mount point /mnt/pi-rootfs. I have also set the symlinks to be relative using the script sysroot-relativelinks.py.

The qtbase configuration was called with the following argument:

./configure -opengl es2 -device linux-rpi3-g++ -device-option 
CROSS_COMPILE=/home/osboxes/Downloads/gcc-linaro-6.3.1-2017.05-x86_64_arm-linux-gnueabihf/bin/arm-linux-gnueabihf- 
-sysroot /mnt/pi-rootfs -opensource -confirm-license -optimized-qmake 
-reduce-exports -release -make libs -prefix /usr/local/qt5pi 
-hostprefix /usr/local/qt5pi

This configures qt but no openGL and I have the message:

ERROR: Feature 'opengles2' was enabled, but the pre-condition 'config.win32 || (!config.watchos && !features.opengl-desktop && libs.opengl_es2)' failed.

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.

Check config.log for details.

Looking at the config file, I have:

> /home/osboxes/Downloads/gcc-linaro-6.3.1-2017.05-x86_64_arm-linux-gnueabihf/bin/arm-linux-gnueabihf-g++ -c -march=armv8-a -mtune=cortex-a53 -mfpu=crypto-neon-fp-armv8 -mfloat-abi=hard --sysroot=/mnt/pi-rootfs --sysroot=/mnt/pi-rootfs -O2 -Wall -W -fPIC  -I. -I/opt/vc/include -I/opt/vc/include/interface/vcos/pthreads -I/opt/vc/include/interface/vmcs_host/linux -I/home/osboxes/Downloads/qt5/qtbase/mkspecs/devices/linux-rpi3-g++ -o opengles2.o opengles2.cpp
> opengles2.cpp:44:25: fatal error: GLES2/gl2.h: No such file or directory
>    #include <GLES2/gl2.h>
>                          ^
> compilation terminated.
> Makefile:179: recipe for target 'opengles2.o' failed
> make: *** [opengles2.o] Error 1
 => source failed verification.
test config.gui.libraries.opengl_es2 FAILED

So, it does not set the paths correctly, so I edited the mkspecs file for linux-rpi3-g++. So, the relevant part of the file looks like:

QMAKE_LFLAGS           += -Wl,-rpath-link,$$[QT_SYSROOT]/opt/vc/lib

VC_LIBRARY_PATH         = /opt/vc/lib
VC_INCLUDE_PATH         = /opt/vc/include

# terrible, they do not appear to resolve "=" in rpath!
VC_LINK_LINE            = -L=$${VC_LIBRARY_PATH} -Wl,-rpath-link,$$[QT_SYSROOT]$${VC_LIBRARY_PATH}

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_LIBS_OPENGL_ES2   = $${VC_LINK_LINE} -lGLESv2

# The official opt vc EGL references GLESv2 symbols: need to link it
QMAKE_LIBS_EGL          = $${VC_LINK_LINE} -lEGL -lGLESv2

So, I tried various things which all included adding $$[QT_SYSROOT] prefix at various places for example at VC_LIBRARY_PATH and VC_INCLUDE_PATH and even though I got it to find the include path it could not like to the GLES2 libraries (I have verified the libs are indeed at the correct location: /mnt/pi-rootfs/opt/vc/lib).

I wonder if someone has suggestions on how to solve this hopefully without editing qt mkspecs files and doing other such hacks.

EDIT So, I modified the mkspecs file as follows:

QMAKE_LFLAGS           += -Wl,-rpath-link,$$[QT_SYSROOT]/opt/vc/lib

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

# terrible, they do not appear to resolve "=" in rpath!
VC_LINK_LINE            = -L=$${VC_LIBRARY_PATH} -Wl,-rpath-link,$$[QT_SYSROOT]$${VC_LIBRARY_PATH}

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_LIBS_OPENGL_ES2   = $${VC_LINK_LINE} -lGLESv2  #original
QMAKE_LIBS_OPENGL_ES2   = -lGLESv2  #changed

# The official opt vc EGL references GLESv2 symbols: need to link it
#QMAKE_LIBS_EGL          = $${VC_LINK_LINE} -lEGL -lGLESv2 #original
QMAKE_LIBS_EGL          = -lEGL -lGLESv2  #changed

And this results in the linking error when trying to find gles:

> /home/osboxes/Downloads/gcc-linaro-6.3.1-2017.05-x86_64_arm-linux-gnueabihf/bin/arm-linux-gnueabihf-g++ -Wl,-rpath-link,/mnt/pi-rootfs/opt/vc/lib -Wl,-rpath-link,/mnt/pi-rootfs/usr/lib/arm-linux-gnueabihf -Wl,-rpath-link,/mnt/pi-rootfs/lib/arm-linux-gnueabihf -mfloat-abi=hard --sysroot=/mnt/pi-rootfs --sysroot=/mnt/pi-rootfs -Wl,-O1 -fuse-ld=gold -o opengles2 opengles2.o   -L=/mnt/pi-rootfs/opt/vc/lib -lGLESv2 
> /home/osboxes/Downloads/gcc-linaro-6.3.1-2017.05-x86_64_arm-linux-gnueabihf/bin/../lib/gcc/arm-linux-gnueabihf/6.3.1/../../../../arm-linux-gnueabihf/bin/ld.gold: error: cannot find -lGLESv2
> opengles2.o:opengles2.cpp:function main: error: undefined reference to 'glUniform1f'
> opengles2.o:opengles2.cpp:function main: error: undefined reference to 'glClear'
> collect2: error: ld returned 1 exit status
> Makefile:65: recipe for target 'opengles2' failed

The path -L=/mnt/pi-rootfs/opt/vc/lib is correct and I verify that this is where the glesv2 library resides.


回答1:


This is the qmake.conf I used (it worked for me):

include(../common/linux_device_pre.conf)

QMAKE_LFLAGS           += -Wl,-rpath-link,$$[QT_SYSROOT]/opt/vc/lib
QMAKE_LFLAGS           += -Wl,-rpath-link,$$[QT_SYSROOT]/home/pi/qtdeps/lib

QMAKE_LIBDIR_OPENGL_ES2 = $$[QT_SYSROOT]/opt/vc/lib
QMAKE_LIBDIR_EGL        = $$QMAKE_LIBDIR_OPENGL_ES2
QMAKE_LIBDIR_OPENVG     = $$QMAKE_LIBDIR_OPENGL_ES2

QMAKE_INCDIR_EGL        = $$[QT_SYSROOT]/opt/vc/include \
                          $$[QT_SYSROOT]/opt/vc/include/interface/vcos/pthreads \
                          $$[QT_SYSROOT]/opt/vc/include/interface/vmcs_host/linux

QMAKE_INCDIR_OPENGL_ES2 = $${QMAKE_INCDIR_EGL}
QMAKE_INCDIR_OPENVG     = $${QMAKE_INCDIR_EGL}

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

QMAKE_CFLAGS            = -march=armv8-a -mtune=cortex-a53 -mfpu=crypto-neon-fp-armv8
QMAKE_CXXFLAGS          = $$QMAKE_CFLAGS

DISTRO_OPTS            += hard-float
DISTRO_OPTS            += deb-multi-arch

# Preferred eglfs backend
EGLFS_DEVICE_INTEGRATION= eglfs_brcm

include(../common/linux_arm_device_post.conf)

load(qt_config)



回答2:


In Raspbian Stretch "rpi-update" must be invoked, otherwise "libGLESv2.so" is missing in /opt/vc/lib. This fixes the linker error "cannot find -lGLESv2"

https://www.raspberrypi.org/forums/viewtopic.php?t=191638

update: the previously mentioned solution may have some unwanted side effects. I therefore recommend doing this instead::

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



回答3:


My starting point was 2017-11-29-raspbian-stretch and built my toolchain in OSX using crosstool-ng.

While sudo rpi-update helped and brought in 'libGLESv2.so', it did not solve the problem for me. The issue turned out to be in the QT configuration. QT uses gcc -dumpmachine to establish the tuple. For me it was 'arm-raspbian-linux-gnueabihf'. QT ends up searching for libraries and packages in locations like /usr/lib/arm-raspbian-linux-gnueabihf which do not exist. (It ends up failing to find libraries like 'libpthread.so' while compiling using GLESv2.) Instead, if you look at the OS, the correct location is /usr/lib/arm-linux-gnueabihf. The solution is to modify 'configure.pri' in qtbase.

--- a/configure.pri
+++ b/configure.pri
@@ -241,7 +241,7 @@ defineReplace(qtConfFunc_licenseCheck) {

 # this is meant for linux device specs only
 defineTest(qtConfTest_machineTuple) {
-    qtRunLoggedCommand("$$QMAKE_CXX -dumpmachine", $${1}.tuple)|return(false)
+    qtRunLoggedCommand("$$QMAKE_CXX -dumpmachine | sed 's/-raspbian//'", $${1}.tuple)|return(false)
     $${1}.cache += tuple
     export($${1}.cache)
     return(true)

This changes the tuple from crosstool-ng to the triplet.

Update. If you are using crosstool-ng, an alternative to this "fix" is to use CT_TARGET=arm-linux-gnueabihf (not CT_TARGET_ALIAS).



来源:https://stackoverflow.com/questions/44639014/qt-cross-compilation-for-raspberry-pi-cannot-find-glesv2

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!