Qt5使用CMake交叉编译树莓派

时间:2018-09-20 10:07:24

标签: c++ cmake raspberry-pi qt5 cross-compiling

我正在尝试使用CMake将qt5程序交叉编译到树莓派,并且无法通过错误:Failed to find "GL/gl.h" in "/usr/include/libdrm"。 我将发布我所做的所有事情,希望有人能提供帮助。

我的CMakeLists.txt文件:

cmake_minimum_required(VERSION 2.8)

project(RPQT_server)
set(Qt5_DIR "/home/int-krta/Qt/5.11.1/gcc_64/lib/cmake/Qt5")
set(CMAKE_INCLUDE_CURRENT_DIR ON)
find_package(Qt5 COMPONENTS Widgets Network CONFIG REQUIRED)
file(GLOB HEADERS "include/*.h")
file(GLOB SOURCES "src/*.cpp")

set(RPQT_server_SRCS ${SOURCES})
set(RPQT_server_MOC_HDRS ${HEADERS})

qt5_wrap_cpp(RPQT_server_CPP_FILES ${RPQT_server_MOC_HDRS})

add_executable(${PROJECT_NAME} ${RPQT_server_SRCS} ${RPQT_server_CPP_FILES})

set(RPQT_server_HEADER_DIR ${CMAKE_CURRENT_SOURCE_DIR}/include)
include_directories(${RPQT_server_HEADER_DIR})

target_link_libraries(RPQT_server Qt5::Widgets Qt5::Network)

我的Toolchain.cmake文件:

set(CMAKE_SYSTEM_NAME Linux)

SET(CMAKE_C_COMPILER $ENV{HOME}/crosscompile_toolchain/tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian/bin/arm-linux-gnueabihf-gcc)
SET(CMAKE_CXX_COMPILER $ENV{HOME}/crosscompile_toolchain/tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian/bin/arm-linux-gnueabihf-g++)

SET(CMAKE_FIND_ROOT_PATH $ENV{HOME}/crosscompile_toolchain/rootfs)
SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} --sysroot=${CMAKE_FIND_ROOT_PATH}")
SET(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} --sysroot=${CMAKE_FIND_ROOT_PATH}")
SET(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} --sysroot=${CMAKE_FIND_ROOT_PATH}")

SET(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)

SET(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
SET(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)

INCLUDE_DIRECTORIES($ENV{HOME}/crosscompile_toolchain/rootfs/opt/vc/include)
INCLUDE_DIRECTORIES($ENV{HOME}/crosscompile_toolchain/rootfs/opt/vc/include/interface/vcos/pthreads)
INCLUDE_DIRECTORIES($ENV{HOME}/crosscompile_toolchain/rootfs/opt/vc/include/interface/vmcs_host/linux)

我正在运行以下cmake命令:

cmake -D CMAKE_BUILD_TYPE=Debug -D CMAKE_TOOLCHAIN_FILE=$HOME/crosscompile_toolchain/Toolchain-RaspberryPi.cmake $HOME/training_projects/RPQT_server

有输出:

-- The C compiler identification is GNU 4.8.3
-- The CXX compiler identification is GNU 4.8.3
-- Check for working C compiler: /home/int-krta/crosscompile_toolchain/tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian-x64/bin/arm-linux-gnueabihf-gcc
-- Check for working C compiler: /home/int-krta/crosscompile_toolchain/tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian-x64/bin/arm-linux-gnueabihf-gcc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /home/int-krta/crosscompile_toolchain/tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian-x64/bin/arm-linux-gnueabihf-g++
-- Check for working CXX compiler: /home/int-krta/crosscompile_toolchain/tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian-x64/bin/arm-linux-gnueabihf-g++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
CMake Error at /home/int-krta/Qt/5.11.1/gcc_64/lib/cmake/Qt5Gui/Qt5GuiConfigExtras.cmake:9 (message):
  Failed to find "GL/gl.h" in "/usr/include/libdrm".
Call Stack (most recent call first):
  /home/int-krta/Qt/5.11.1/gcc_64/lib/cmake/Qt5Gui/Qt5GuiConfig.cmake:171 (include)
  /home/int-krta/Qt/5.11.1/gcc_64/lib/cmake/Qt5Widgets/Qt5WidgetsConfig.cmake:89 (find_package)
  /home/int-krta/Qt/5.11.1/gcc_64/lib/cmake/Qt5/Qt5Config.cmake:28 (find_package)
  CMakeLists.txt:6 (find_package)


-- Configuring incomplete, errors occurred!
See also "/home/int-krta/crosscompile_toolchain/build/CMakeFiles/CMakeOutput.log".

我已经安装了像mesa-common-dev之类的库以及其他一些库,没有任何帮助。难道我做错了什么?还是我错过了什么?

编辑: 由于Tsyvarev的评论,我设法在TARGET机器(即Raspberry Pi)上安装了正确的库,从而解决了该错误,因此现在cmake成功并保存了构建文件,但是当我尝试使用make时,我有了这个链接错误:

/home/int-krta/Qt/5.11.1/gcc_64/lib/libQt5Widgets.so.5.11.1: file not recognized: File format not recognized 

如果找到了很好的解决方案,则需要立即制作Qt版本,因此在qtbase文件夹中运行命令:

./configure -release -opengl es2 -device linux-rasp-pi-g++ -device-option CROSS_COMPILE=$HOME/crosscompile_toolchain/tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian/bin/arm-linux-gnueabihf- -sysroot /media/int-krta/rootfs -prefix /usr/local/qt5pi -no-gcc-sysroot -opensource -confirm-license

我明白了,不知道下一步该怎么做:

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.

我做错了什么还是什么,有人可以指导我下一步做什么吗?

0 个答案:

没有答案