admin管理员组

文章数量:1355581

Hi I am cross compiling form a x86 ubuntu machine to are armv8 environment. I am using QT6. I have followed this guide as a starting point to build qt6 for for my host and target. This has been successful. My toolchain.cmake file is shown below.

The target is a raspberry pi 4. The ultimate aim is to have the cross compile environment in a (docker) container and the raspberry pi image to be as close to the standard raspberry pi image as possible with just a few packages installed from apt and our software installed

As you can see I am using aarch64-linux-gnu-g++-12 as my compiler. This is because when compiling a simple C++ hello world I discovered the target had libstdc++ with GLIBCXX_3.4.30 and GLIBC_2.34. This is the version of libstdc++.so installed with aarch64-linux-gnu-g++-12 (located in /usr/lib/gcc-cross/aarch64-linux-gnu/12/) and matches the version on my target. I can also see on the target that 12 is the latest g++ version installed on target. All good for libcstd++

The problem I have is that when I cross compile qt is relies on libc.so, which for some reason installing aarch64-linux-gnu-g++-12 doesn't install a separate version as it does for libstd++.so so links against the version in /usr/aarch64-linux-gnu/lib/ which has GLIBC_2.39 but the target only has GLIBC_2.36 available.

The solutions I see are:

  1. Copy over the libc.so.6 from my cross compile environment to target.
  2. Compile a new version of libc.so for target
  3. Compile a version of libc.so for cross compile environment
  4. Hunt around in the qt cmake file and force it to statically link libc.

Out of these #1 is appealing as it means the docker image still just relies on stuff from apt but not good given our aim of minimum deviation form the standard rpi image. Whereas the other two require more fiddling and keeping things up to date and looking at the size size of the qt project I am intimidated by #4.

So I guess my questions are.

  1. Any idea why aarch64-linux-gnu-g++-12 not supply a different version of libc is it does for libstdc++?
  2. Is there a another way other that compiling libc to get an older version on my cross compile env? I know to get a new version I have to compile but rolling back?
  3. Any other solution?

EDIT: target gcc -v -> 12.20 xcompile env gcc -v -> 12.30

toolchain.cmake below.

cmake_minimum_required(VERSION 3.18)                              
include_guard(GLOBAL)                                             
                                                                  
set(CMAKE_SYSTEM_NAME Linux)                                      
set(CMAKE_SYSTEM_PROCESSOR arm)                                   
                                                                  
set(TARGET_SYSROOT /home/tommy/projects/rPi4_OS/crossCompile/rpi-s
set(CMAKE_SYSROOT ${TARGET_SYSROOT})                              
                                                                  
set(ENV{PKG_CONFIG_PATH} $PKG_CONFIG_PATH:/usr/lib/pkgconfig)     
set(ENV{PKG_CONFIG_LIBDIR} /usr/lib/pkgconfig:/usr/share/pkgconfig
set(ENV{PKG_CONFIG_SYSROOT_DIR} ${CMAKE_SYSROOT})                 
                                                                  
# if you use other version of gcc and g++ than gcc/g++ 12, you mus
set(CMAKE_C_COMPILER /usr/bin/aarch64-linux-gnu-gcc-12)           
set(CMAKE_CXX_COMPILER /usr/bin/aarch64-linux-gnu-g++-12)         
                                                                  
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -I${TARGET_SYSROOT}/usr/includ
set(CMAKE_CXX_FLAGS "${CMAKE_C_FLAGS}")                           
                                                                  
set(QT_COMPILER_FLAGS "-march=armv8-a")                           
set(QT_COMPILER_FLAGS_RELEASE "-O2 -pipe -DNDEBUG")               
set(QT_LINKER_FLAGS "-Wl,-O1 -Wl,--hash-style=gnu -Wl,--as-needed"
                                                                  
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)                       
set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)                       
set(CMAKE_BUILD_RPATH ${TARGET_SYSROOT})                          
                                                                  
                                                                  
include(CMakeInitializeConfigs)                                   
                                                                  
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_FLA
      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()                                                             
                                                                          
set(XCB_PATH_VARIABLE ${TARGET_SYSROOT})                                  
                                                                          
set(GL_INC_DIR ${TARGET_SYSROOT}/usr/include)                             
set(GL_LIB_DIR ${TARGET_SYSROOT}:${TARGET_SYSROOT}/usr/lib/aarch64-linux-g
                                                                          
set(EGL_INCLUDE_DIR ${GL_INC_DIR})                                        
set(EGL_LIBRARY ${XCB_PATH_VARIABLE}/usr/lib/aarch64-linux-gnu/libEGL.so) 
                                                                          
set(OPENGL_INCLUDE_DIR ${GL_INC_DIR})                                     
set(OPENGL_opengl_LIBRARY ${XCB_PATH_VARIABLE}/usr/lib/aarch64-linux-gnu/l
                                                                          
set(GLESv2_INCLUDE_DIR ${GL_INC_DIR})                                     
set(GLESv2_LIBRARY ${XCB_PATH_VARIABLE}/usr/lib/aarch64-linux-gnu/libGLESv
                                                                          
set(gbm_INCLUDE_DIR ${GL_INC_DIR})                                        
set(gbm_LIBRARY ${XCB_PATH_VARIABLE}/usr/lib/aarch64-linux-gnu/libgbm.so)

set(Libdrm_INCLUDE_DIR ${GL_INC_DIR})
set(Libdrm_LIBRARY ${XCB_PATH_VARIABLE}/usr/lib/aarch64-linux-gnu/libdrm.so)

set(XCB_XCB_INCLUDE_DIR ${GL_INC_DIR})
set(XCB_XCB_LIBRARY ${XCB_PATH_VARIABLE}/usr/lib/aarch64-linux-gnu/libxcb.so) 

本文标签: cCross compiling GLIBC mismatch but ok for GLIBCXXStack Overflow