初中生
最后登录1970-1-1
在线时间 小时
注册时间2024-11-22
|
参考资料:https://doc.embedfire.com/linux/ ... /install_arm_3.html Qt开发环境交叉编译
目的:基于上面的教程,进行Qt6.7.3关于armhf架构的交叉编译。
当前环境:目标设备(Zynq):ubuntu18.04,ppa升级编译器为11.4.0;宿主机:ubuntu18.04,ppa升级编译器11.4.0;
当前我是能在宿主机上完成主机端的源码编译,运行正常。但是进行交叉编译时,我仿照教程设置了sysroot,以及toolchain.cmake和qmake.conf。但是运行时报错找不到相关的C启动文件库,编译器无法进行简单文件编译:
- cmake ../qt-everywhere-src-6.7.3/ -GNinja -DCMAKE_BUILD_TYPE=Release -DINPUT_opengl=es2 -DQT_BUILD_EXAMPLES=OFF -DQT_BUILD_TESTS=OFF -DQT_HOST_PATH=$HOME/qt/qt6Host -DCMAKE_STAGING_PREFIX=$HOME/sysroot/opt/prefix -DCMAKE_INSTALL_PREFIX=$HOME/sysroot/opt/prefix -DCMAKE_TOOLCHAIN_FILE=$HOME/qt/toolchain.cmake -DQT_QMAKE_TARGET_MKSPEC=devices/linux-zynq-g++ -DQT_FEATURE_xcb=ON -DFEATURE_xcb_xlib=ON -DQT_FEATURE_xlib=ON -DFEATURE_qtwebengine_build=OFF
- -- The CXX compiler identification is GNU 11.3.1
- -- The C compiler identification is GNU 11.3.1
- -- The ASM compiler identification is GNU
- -- Found assembler: /opt/arm-gnu-toolchain-11.3.rel1-x86_64-arm-none-linux-gnueabihf/bin/arm-none-linux-gnueabihf-gcc
- -- Detecting CXX compiler ABI info
- -- Detecting CXX compiler ABI info - failed
- -- Check for working CXX compiler: /opt/arm-gnu-toolchain-11.3.rel1-x86_64-arm-none-linux-gnueabihf/bin/arm-none-linux-gnueabihf-g++
- -- Check for working CXX compiler: /opt/arm-gnu-toolchain-11.3.rel1-x86_64-arm-none-linux-gnueabihf/bin/arm-none-linux-gnueabihf-g++ - broken
- <font color="#ff0000">CMake Error at /home/lucasyuen/Qt6.7.3/Tools/CMake/share/cmake-3.29/Modules/CMakeTestCXXCompiler.cmake:73 (message):
- The C++ compiler
- "/opt/arm-gnu-toolchain-11.3.rel1-x86_64-arm-none-linux-gnueabihf/bin/arm-none-linux-gnueabihf-g++"
- is not able to compile a simple test program.
- It fails with the following output:
- Change Dir: '/home/lucasyuen/qt/qt6-cross/build/CMakeFiles/CMakeScratch/TryCompile-5MWA5S'
-
- Run Build Command(s): /home/lucasyuen/Qt6.7.3/Tools/Ninja/ninja -v cmTC_1591e
- [1/2] /opt/arm-gnu-toolchain-11.3.rel1-x86_64-arm-none-linux-gnueabihf/bin/arm-none-linux-gnueabihf-g++ --sysroot=/home/lucasyuen/sysroot -fPIC -Wl,-rpath-link,/home/lucasyuen/sysroot/lib/arm-linux-gnueabihf -fPIC -Wl,-rpath-link,/home/lucasyuen/sysroot/usr/lib/arm-linux-gnueabihf -L/home/lucasyuen/sysroot/lib -L/home/lucasyuen/sysroot/lib/arm-linux-gnueabihf -L/home/lucasyuen/sysroot/usr/lib/arm-linux-gnueabihf -L/home/lucasyuen/sysroot/usr/lib -I/home/lucasyuen/sysroot/usr/include -I/home/lucasyuen/sysroot/usr/include/arm-linux-gnueabihf -o CMakeFiles/cmTC_1591e.dir/testCXXCompiler.cxx.o -c /home/lucasyuen/qt/qt6-cross/build/CMakeFiles/CMakeScratch/TryCompile-5MWA5S/testCXXCompiler.cxx
- [2/2] : && /opt/arm-gnu-toolchain-11.3.rel1-x86_64-arm-none-linux-gnueabihf/bin/arm-none-linux-gnueabihf-g++ --sysroot=/home/lucasyuen/sysroot -fPIC -Wl,-rpath-link,/home/lucasyuen/sysroot/lib/arm-linux-gnueabihf -fPIC -Wl,-rpath-link,/home/lucasyuen/sysroot/usr/lib/arm-linux-gnueabihf -L/home/lucasyuen/sysroot/lib -L/home/lucasyuen/sysroot/lib/arm-linux-gnueabihf -L/home/lucasyuen/sysroot/usr/lib/arm-linux-gnueabihf -L/home/lucasyuen/sysroot/usr/lib -I/home/lucasyuen/sysroot/usr/include -I/home/lucasyuen/sysroot/usr/include/arm-linux-gnueabihf -Wl,-O1 -Wl,--hash-style=gnu -Wl,--as-needed -Wl,-fuse-ld=gold -ldbus-1 CMakeFiles/cmTC_1591e.dir/testCXXCompiler.cxx.o -o cmTC_1591e && :
- FAILED: cmTC_1591e
- : && /opt/arm-gnu-toolchain-11.3.rel1-x86_64-arm-none-linux-gnueabihf/bin/arm-none-linux-gnueabihf-g++ --sysroot=/home/lucasyuen/sysroot -fPIC -Wl,-rpath-link,/home/lucasyuen/sysroot/lib/arm-linux-gnueabihf -fPIC -Wl,-rpath-link,/home/lucasyuen/sysroot/usr/lib/arm-linux-gnueabihf -L/home/lucasyuen/sysroot/lib -L/home/lucasyuen/sysroot/lib/arm-linux-gnueabihf -L/home/lucasyuen/sysroot/usr/lib/arm-linux-gnueabihf -L/home/lucasyuen/sysroot/usr/lib -I/home/lucasyuen/sysroot/usr/include -I/home/lucasyuen/sysroot/usr/include/arm-linux-gnueabihf -Wl,-O1 -Wl,--hash-style=gnu -Wl,--as-needed -Wl,-fuse-ld=gold -ldbus-1 CMakeFiles/cmTC_1591e.dir/testCXXCompiler.cxx.o -o cmTC_1591e && :
- /opt/arm-gnu-toolchain-11.3.rel1-x86_64-arm-none-linux-gnueabihf/bin/../lib/gcc/arm-none-linux-gnueabihf/11.3.1/../../../../arm-none-linux-gnueabihf/bin/ld.gold: error: cannot open crt1.o: 没有那个文件或目录
- /opt/arm-gnu-toolchain-11.3.rel1-x86_64-arm-none-linux-gnueabihf/bin/../lib/gcc/arm-none-linux-gnueabihf/11.3.1/../../../../arm-none-linux-gnueabihf/bin/ld.gold: error: cannot open crti.o: 没有那个文件或目录
- /opt/arm-gnu-toolchain-11.3.rel1-x86_64-arm-none-linux-gnueabihf/bin/../lib/gcc/arm-none-linux-gnueabihf/11.3.1/../../../../arm-none-linux-gnueabihf/bin/ld.gold: error: cannot open crtn.o: 没有那个文件或目录
- /opt/arm-gnu-toolchain-11.3.rel1-x86_64-arm-none-linux-gnueabihf/bin/../lib/gcc/arm-none-linux-gnueabihf/11.3.1/../../../../arm-none-linux-gnueabihf/bin/ld.gold: error: cannot open /home/lucasyuen/sysroot/usr/lib/arm-linux-gnueabihf/libm.so: 没有那个文件或目录
- collect2: error: ld returned 1 exit status
- ninja: build stopped: subcommand failed.
- CMake will not be able to correctly generate this project.
- Call Stack (most recent call first):
- CMakeLists.txt:15 (project)
- </font>
- 我的toolchain.cmake配置如下:
- <div class="blockcode"><blockquote># 设置 cmake 支持的最小版本
- cmake_minimum_required(VERSION 3.18)
- include_guard(GLOBAL)
- # 设置目标系统为 Linux 和目标架构为 ARM
- set(CMAKE_SYSTEM_NAME Linux)
- set(CMAKE_SYSTEM_PROCESSOR arm)
- # 指定sysroot目录
- set(TARGET_SYSROOT /home/lucasyuen/sysroot)
- # 指定前面获取的交叉编译器路径
- set(CROSS_COMPILER /opt/arm-gnu-toolchain-11.3.rel1-x86_64-arm-none-linux-gnueabihf/bin/arm-none-linux-gnueabihf)
- # 编译器和链接器应使用的根文件系统路径
- set(CMAKE_SYSROOT ${TARGET_SYSROOT})
- # 设置编译器
- set(CMAKE_C_COMPILER ${CROSS_COMPILER}-gcc)
- set(CMAKE_CXX_COMPILER ${CROSS_COMPILER}-g++)
- # 设置体系结构
- set(CMAKE_LIBRARY_ARCHITECTURE arm-linux-gnueabihf)
- # 设置库路径
- set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fPIC -Wl,-rpath-link,${CMAKE_SYSROOT}/lib/${CMAKE_LIBRARY_ARCHITECTURE} -fPIC -Wl,-rpath-link,${CMAKE_SYSROOT}/usr/lib/${CMAKE_LIBRARY_ARCHITECTURE} -L${CMAKE_SYSROOT}/lib -L${CMAKE_SYSROOT}/lib/${CMAKE_LIBRARY_ARCHITECTURE} -L${CMAKE_SYSROOT}/usr/lib/${CMAKE_LIBRARY_ARCHITECTURE} -L${CMAKE_SYSROOT}/usr/lib -I${TARGET_SYSROOT}/usr/include -I${TARGET_SYSROOT}/usr/include/${CMAKE_LIBRARY_ARCHITECTURE}")
- set(CMAKE_CXX_FLAGS "${CMAKE_C_FLAGS}")
- # 设置 pkg-config 环境变量
- set(ENV{PKG_CONFIG_PATH} ${TARGET_SYSROOT}/usr/lib/pkgconfig:${TARGET_SYSROOT}/usr/lib/${CMAKE_LIBRARY_ARCHITECTURE}/pkgconfig:${TARGET_SYSROOT}/usr/share/pkgconfig/)
- set(ENV{PKG_CONFIG_LIBDIR} ${TARGET_SYSROOT}/usr/lib/pkgconfig:${TARGET_SYSROOT}/usr/lib/${CMAKE_LIBRARY_ARCHITECTURE}/pkgconfig:${TARGET_SYSROOT}/usr/share/pkgconfig/)
- set(ENV{PKG_CONFIG_SYSROOT_DIR} ${CMAKE_SYSROOT})
- # 设置 Qt 编译和链接选项
- set(QT_COMPILER_FLAGS "-march=armv7-a")
- set(QT_COMPILER_FLAGS_RELEASE "-O2 -pipe")
- set(QT_LINKER_FLAGS "-Wl,-O1 -Wl,--hash-style=gnu -Wl,--as-needed -Wl,-fuse-ld=gold -ldbus-1")
- # 配置查找路径模式
- set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
- set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
- set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
- set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY)
- include(CMakeInitializeConfigs)
- # 为不同的构建配置(如 DEBUG, RELEASE)初始化编译器和链接器标志
- function(cmake_initialize_per_config_variable _PREFIX _DOCSTRING)
- if (_PREFIX MATCHES "CMAKE_(C|CXX|ASM)_FLAGS")
- set(CMAKE_${CMAKE_MATCH_1}_FLAGS_INIT "${QT_COMPILER_FLAGS}")
- foreach (config DEBUG RELEASE MINSIZEREL RELWITHDEBINFO)
- if (DEFINED QT_COMPILER_FLAGS_${config})
- set(CMAKE_${CMAKE_MATCH_1}_FLAGS_${config}_INIT "${QT_COMPILER_FLAGS_${config}}")
- endif()
- endforeach()
- endif()
- if (_PREFIX MATCHES "CMAKE_(SHARED|MODULE|EXE)_LINKER_FLAGS")
- foreach (config SHARED MODULE EXE)
- set(CMAKE_${config}_LINKER_FLAGS_INIT "${QT_LINKER_FLAGS}")
- endforeach()
- endif()
- _cmake_initialize_per_config_variable(${ARGV})
- endfunction()
复制代码 qmake.conf如下:- #
- # qmake configuration for the Zynq running Linux for Ubuntu18.04
- #
- # 通用的预设配置文件
- include(../common/linux_device_pre.conf)
- # 设置OpenGL和EGL库
- QMAKE_LIBS_EGL += -lEGL -lmali
- QMAKE_LIBS_OPENGL_ES2 += -lGLESv2 -lEGL -lmali
- # 设置编译选项
- QMAKE_CFLAGS = -march=armv7-a
- QMAKE_CXXFLAGS = $$QMAKE_CFLAGS
- # 链接器选项
- QMAKE_LFLAGS += -static-libstdc++
- # 设置包含目录(Include Directories)
- QMAKE_INCDIR_POST += $$[QT_SYSROOT]/usr/include $$[QT_SYSROOT]/usr/include/arm-linux-gnueabihf/
- # 设置库目录(Library Directories)
- QMAKE_LIBDIR_POST += $$[QT_SYSROOT]/usr/lib $$[QT_SYSROOT]/lib/$${GCC_MACHINE_DUMP} $$[QT_SYSROOT]/usr/lib/$${GCC_MACHINE_DUMP}
- # 设置 RPATH 链接目录(Runtime Library Search Path)
- QMAKE_RPATHLINKDIR_POST += $$[QT_SYSROOT]/usr/lib $$[QT_SYSROOT]/usr/lib/$${GCC_MACHINE_DUMP} $$[QT_SYSROOT]/lib/$${GCC_MACHINE_DUMP}
- # 分发选项
- DISTRO_OPTS += armv7
- DISTRO_OPTS += deb-multi-arch
- # 引入后处理配置 ( 通常包含针对 ARM 设备的特定设置(例如库路径、工具链等))
- include(../common/linux_arm_device_post.conf)
- # 加载Qt配置
- load(qt_config)
复制代码 从上面的报错来看是编译器找不到相关文件,但是我核对了一下,感觉toolchain中设置的库路径没什么问题,而且sysroot中的确能找到。所以不知道该怎么解决这个问题,请教下大佬们。
|
|