用于覆盆子pi的qt交叉编译:找不到GLESv2

时间:2017-06-19 20:05:12

标签: qt opengl-es raspberry-pi cross-compiling qmake

我正在尝试为我的raspberry pi 3计算模块编译qt 5.9,我一直在这里主要关注在线指南(https://wiki.qt.io/RaspberryPi2EGLFS)。所以,我已经将pi系统根设置为挂载点/mnt/pi-rootfs。我还使用脚本sysroot-relativelinks.py将符号链接设置为相对的。

使用以下参数调用qtbase配置:

./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

这配置qt但没有openGL,我有消息:

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.

查看配置文件,我有:

> /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

因此,它没有正确设置路径,所以我编辑了mkspecs的{​​{1}}文件。因此,该文件的相关部分如下所示:

linux-rpi3-g++

所以,我尝试了各种各样的事情,其中​​包括在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 $$[QT_SYSROOT]等不同位置添加VC_LIBRARY_PATH前缀,即使我找到它也找不到包含路径喜欢GLES2库(我已经验证了libs确实位于正确的位置:VC_INCLUDE_PATH)。

我想知道是否有人建议如何在不编辑qt mkspecs文件和进行其他此类黑客攻击的情况下解决这个问题。

修改 所以,我按如下方式修改了mkspecs文件:

/mnt/pi-rootfs/opt/vc/lib

这会在尝试查找gles时导致链接错误:

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

路径> /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 是正确的,我确认这是glesv2库所在的位置。

3 个答案:

答案 0 :(得分:5)

在Raspbian Stretch中,必须调用“rpi-update”,否则/ opt / vc / lib中缺少“libGLESv2.so”。这修复了链接器错误“找不到-lGLESv2”

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

答案 1 :(得分:2)

这是我使用的qmake.conf(它对我有用):

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 :(得分:1)

我的出发点是2017-11-29-raspbian-stretch并使用crosstool-ng在OSX中构建我的工具链。

虽然sudo rpi-update帮助并引入了libGLESv2.so&#39;但它并没有为我解决问题。该问题最终出现在QT配置中。 QT使用gcc -dumpmachine来建立元组。对我来说,它是'arm-raspbian-linux-gnueabihf&#39;。 QT最终在/usr/lib/arm-raspbian-linux-gnueabihf等不存在的位置搜索库和包。 (在使用GLESv2进行编译时,最终无法找到类似&#39; libpthread.so&#39;等库。)相反,如果查看操作系统,则正确的位置为/usr/lib/arm-linux-gnueabihf。解决方案是修改&quot; configure.pri&#39;在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)

这会将元组从crosstool-ng更改为三元组。

更新。如果您使用的是crosstool-ng,则替代此&#34;修复&#34;是使用CT_TARGET = arm-linux-gnueabihf(不是CT_TARGET_ALIAS)。