野火电子论坛

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 186|回复: 3

[求助] 基于Qt6的交叉编译,C启动文件始终找不到相应的库

[复制链接]
发表于 2024-11-22 17:03:49 | 显示全部楼层 |阅读模式
参考资料: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启动文件库,编译器无法进行简单文件编译:
  1. 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
  2. -- The CXX compiler identification is GNU 11.3.1
  3. -- The C compiler identification is GNU 11.3.1
  4. -- The ASM compiler identification is GNU
  5. -- Found assembler: /opt/arm-gnu-toolchain-11.3.rel1-x86_64-arm-none-linux-gnueabihf/bin/arm-none-linux-gnueabihf-gcc
  6. -- Detecting CXX compiler ABI info
  7. -- Detecting CXX compiler ABI info - failed
  8. -- Check for working CXX compiler: /opt/arm-gnu-toolchain-11.3.rel1-x86_64-arm-none-linux-gnueabihf/bin/arm-none-linux-gnueabihf-g++
  9. -- 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
  10. <font color="#ff0000">CMake Error at /home/lucasyuen/Qt6.7.3/Tools/CMake/share/cmake-3.29/Modules/CMakeTestCXXCompiler.cmake:73 (message):
  11.   The C++ compiler

  12.     "/opt/arm-gnu-toolchain-11.3.rel1-x86_64-arm-none-linux-gnueabihf/bin/arm-none-linux-gnueabihf-g++"

  13.   is not able to compile a simple test program.

  14.   It fails with the following output:

  15.     Change Dir: '/home/lucasyuen/qt/qt6-cross/build/CMakeFiles/CMakeScratch/TryCompile-5MWA5S'
  16.    
  17.     Run Build Command(s): /home/lucasyuen/Qt6.7.3/Tools/Ninja/ninja -v cmTC_1591e
  18.     [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
  19.     [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   && :
  20.     FAILED: cmTC_1591e
  21.     : && /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   && :
  22.     /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: 没有那个文件或目录
  23.     /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: 没有那个文件或目录
  24.     /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: 没有那个文件或目录
  25.     /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: 没有那个文件或目录
  26.     collect2: error: ld returned 1 exit status
  27.     ninja: build stopped: subcommand failed.

  28.   CMake will not be able to correctly generate this project.
  29. Call Stack (most recent call first):
  30.   CMakeLists.txt:15 (project)
  31. </font>
  32. 我的toolchain.cmake配置如下:
  33. <div class="blockcode"><blockquote># 设置 cmake 支持的最小版本
  34. cmake_minimum_required(VERSION 3.18)
  35. include_guard(GLOBAL)

  36. # 设置目标系统为 Linux 和目标架构为 ARM
  37. set(CMAKE_SYSTEM_NAME Linux)
  38. set(CMAKE_SYSTEM_PROCESSOR arm)

  39. # 指定sysroot目录
  40. set(TARGET_SYSROOT /home/lucasyuen/sysroot)

  41. # 指定前面获取的交叉编译器路径
  42. set(CROSS_COMPILER /opt/arm-gnu-toolchain-11.3.rel1-x86_64-arm-none-linux-gnueabihf/bin/arm-none-linux-gnueabihf)

  43. # 编译器和链接器应使用的根文件系统路径
  44. set(CMAKE_SYSROOT ${TARGET_SYSROOT})

  45. # 设置编译器
  46. set(CMAKE_C_COMPILER ${CROSS_COMPILER}-gcc)
  47. set(CMAKE_CXX_COMPILER ${CROSS_COMPILER}-g++)

  48. # 设置体系结构
  49. set(CMAKE_LIBRARY_ARCHITECTURE arm-linux-gnueabihf)

  50. # 设置库路径
  51. 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}")
  52. set(CMAKE_CXX_FLAGS "${CMAKE_C_FLAGS}")

  53. # 设置 pkg-config 环境变量
  54. set(ENV{PKG_CONFIG_PATH} ${TARGET_SYSROOT}/usr/lib/pkgconfig:${TARGET_SYSROOT}/usr/lib/${CMAKE_LIBRARY_ARCHITECTURE}/pkgconfig:${TARGET_SYSROOT}/usr/share/pkgconfig/)
  55. set(ENV{PKG_CONFIG_LIBDIR} ${TARGET_SYSROOT}/usr/lib/pkgconfig:${TARGET_SYSROOT}/usr/lib/${CMAKE_LIBRARY_ARCHITECTURE}/pkgconfig:${TARGET_SYSROOT}/usr/share/pkgconfig/)
  56. set(ENV{PKG_CONFIG_SYSROOT_DIR} ${CMAKE_SYSROOT})

  57. # 设置 Qt 编译和链接选项
  58. set(QT_COMPILER_FLAGS "-march=armv7-a")
  59. set(QT_COMPILER_FLAGS_RELEASE "-O2 -pipe")
  60. set(QT_LINKER_FLAGS "-Wl,-O1 -Wl,--hash-style=gnu -Wl,--as-needed -Wl,-fuse-ld=gold -ldbus-1")

  61. # 配置查找路径模式
  62. set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
  63. set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
  64. set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
  65. set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY)

  66. include(CMakeInitializeConfigs)

  67. # 为不同的构建配置(如 DEBUG, RELEASE)初始化编译器和链接器标志
  68. function(cmake_initialize_per_config_variable _PREFIX _DOCSTRING)
  69. if (_PREFIX MATCHES "CMAKE_(C|CXX|ASM)_FLAGS")
  70.    set(CMAKE_${CMAKE_MATCH_1}_FLAGS_INIT "${QT_COMPILER_FLAGS}")

  71.    foreach (config DEBUG RELEASE MINSIZEREL RELWITHDEBINFO)
  72.       if (DEFINED QT_COMPILER_FLAGS_${config})
  73.       set(CMAKE_${CMAKE_MATCH_1}_FLAGS_${config}_INIT "${QT_COMPILER_FLAGS_${config}}")
  74.       endif()
  75.    endforeach()
  76. endif()

  77. if (_PREFIX MATCHES "CMAKE_(SHARED|MODULE|EXE)_LINKER_FLAGS")
  78.    foreach (config SHARED MODULE EXE)
  79.       set(CMAKE_${config}_LINKER_FLAGS_INIT "${QT_LINKER_FLAGS}")
  80.    endforeach()
  81. endif()

  82. _cmake_initialize_per_config_variable(${ARGV})
  83. endfunction()
复制代码
qmake.conf如下:
  1. #
  2. # qmake configuration for the Zynq running Linux for Ubuntu18.04
  3. #

  4. # 通用的预设配置文件
  5. include(../common/linux_device_pre.conf)

  6. # 设置OpenGL和EGL库
  7. QMAKE_LIBS_EGL         += -lEGL -lmali
  8. QMAKE_LIBS_OPENGL_ES2  += -lGLESv2 -lEGL -lmali

  9. # 设置编译选项
  10. QMAKE_CFLAGS            = -march=armv7-a
  11. QMAKE_CXXFLAGS          = $$QMAKE_CFLAGS

  12. # 链接器选项
  13. QMAKE_LFLAGS += -static-libstdc++

  14. # 设置包含目录(Include Directories)
  15. QMAKE_INCDIR_POST +=     $$[QT_SYSROOT]/usr/include     $$[QT_SYSROOT]/usr/include/arm-linux-gnueabihf/

  16. # 设置库目录(Library Directories)
  17. QMAKE_LIBDIR_POST +=     $$[QT_SYSROOT]/usr/lib     $$[QT_SYSROOT]/lib/$${GCC_MACHINE_DUMP}          $$[QT_SYSROOT]/usr/lib/$${GCC_MACHINE_DUMP}

  18. # 设置 RPATH 链接目录(Runtime Library Search Path)
  19. QMAKE_RPATHLINKDIR_POST +=     $$[QT_SYSROOT]/usr/lib     $$[QT_SYSROOT]/usr/lib/$${GCC_MACHINE_DUMP}     $$[QT_SYSROOT]/lib/$${GCC_MACHINE_DUMP}

  20. # 分发选项
  21. DISTRO_OPTS += armv7
  22. DISTRO_OPTS += deb-multi-arch

  23. # 引入后处理配置 ( 通常包含针对 ARM 设备的特定设置(例如库路径、工具链等))
  24. include(../common/linux_arm_device_post.conf)

  25. # 加载Qt配置
  26. load(qt_config)
复制代码
从上面的报错来看是编译器找不到相关文件,但是我核对了一下,感觉toolchain中设置的库路径没什么问题,而且sysroot中的确能找到。所以不知道该怎么解决这个问题,请教下大佬们。


回复

使用道具 举报

发表于 2024-11-25 10:03:26 | 显示全部楼层
回复 支持 反对

使用道具 举报

 楼主| 发表于 2024-11-26 17:54:29 | 显示全部楼层
YiangYiang 发表于 2024-11-25 10:03
https://stackoverflow.com/questions/6329887/how-to-fix-linker-error-cannot-find-crt1-o
试试这里面的 ...

谢谢,但是这里面的回答不适用我当前的情况
回复 支持 反对

使用道具 举报

 楼主| 发表于 7 天前 | 显示全部楼层
还是路径问题,得提供相应的软链接才行。
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

联系站长|手机版|野火电子官网|野火淘宝店铺|野火电子论坛 ( 粤ICP备14069197号 ) 大学生ARM嵌入式2群

GMT+8, 2024-12-5 02:23 , Processed in 0.125773 second(s), 25 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表