Cross-compiling errors with toolchain and targetfs

Hello!

I’am trying to compile my C++ program with Qt for Jetson AGX Orin. First of all, I went and used the following image (is it correct?):

nvcr.io/nvidia/jetpack-linux-aarch64-crosscompile-x86:6.1

Then, using the instruction

cd /l4t cat targetfs.tbz2.* > targetfs.tbz2 tar -I lbzip2 -xf targetfs.tbz2 mkdir toolchain tar -C toolchain -xf toolchain.tar.bz2

I received two folders toolchain and targetfs. Then I have configured Qt and built it, everything was fine. Configure line was something like this:
../qt6/configure
-prefix /opt/qt6-aarch64
-extprefix /opt/qt6-aarch64
-release
-opengl es2
-device linux-aarch64-gnu-g++
-device-option CROSS_COMPILE=/l4t/toolchain/aarch64–glibc–stable-2022.08-1/bin/
-sysroot /l4t/targetfs
-opensource
-confirm-license
-nomake examples
-nomake tests ….

Then I tried to compile my own program and here I have an issue. In CMakeLists I have successfully “included” Qt libraries, set sysroots, cross compiling and so on. Here is CMakeLists’s part about configuration:

make_minimum_required(VERSION 3.16)
project(Client VERSION 1.0.0 LANGUAGES CXX)

set(CMAKE_SYSTEM_NAME Linux)
set(CMAKE_SYSTEM_PROCESSOR aarch64)
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

set(MAKE_FIND_DEBUG_MODE TRUE)
set(QT_DEBUG_FIND_PACKAGE ON)

set(TOOLCHAIN_PATH “/l4t/toolchain/aarch64–glibc–stable-2022.08-1”)
set(TARGETFS_PATH “/l4t/targetfs”)
set(QT6_AARCH64_PATH “/workspace/qt6-aarch64”)

set(CMAKE_THREAD_LIBS_INIT “-lpthread”)
set(CMAKE_HAVE_THREADS_LIBRARY 1)
set(THREADS_FOUND TRUE)


(CMAKE_C_COMPILER “${TOOLCHAIN_PATH}/bin/aarch64-linux-gcc”)

(CMAKE_CXX_COMPILER “${TOOLCHAIN_PATH}/bin/aarch64-linux-g++”)

set(CMAKE_C_COMPILER “${TOOLCHAIN_PATH}/bin/aarch64-buildroot-linux-gnu-gcc”)
set(CMAKE_CXX_COMPILER “${TOOLCHAIN_PATH}/bin/aarch64-buildroot-linux-gnu-g++”)

# Tried boths of them

include_directories(“${TARGETFS_PATH}/usr/include/”)

set(CMAKE_EXE_LINKER_FLAGS “-m64 -ccbin aarch64-linux-gnu-g++”)

set(Qt6_DIR /workspace/qt6-aarch64/lib/cmake/Qt6)

set(CMAKE_FIND_ROOT_PATH “${TARGETFS_PATH}”)
set(CMAKE_SYSROOT “${TARGETFS_PATH}”)

set(CMAKE_C_FLAGS “${CMAKE_C_FLAGS} --sysroot=${TARGETFS_DIR}”)
set(CMAKE_CXX_FLAGS “${CMAKE_CXX_FLAGS} --sysroot=${TARGETFS_DIR}”)

set(CMAKE_${lang}_COMPILE_OPTIONS_SYSROOT “–sysroot=”)

set(CMAKE_${lang}LINKER_WRAPPER_FLAG “-Wl,”)
set(CMAKE${lang}_LINKER_WRAPPER_FLAG_SEP “,”)

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)

list(APPEND CMAKE_PREFIX_PATH “${QT6_AARCH64_PATH}”)
list(APPEND CMAKE_FIND_ROOT_PATH “${QT6_AARCH64_PATH}”)

set(CMAKE_C_FLAGS “${CMAKE_C_FLAGS} -I${TARGETFS_DIR}/usr/include -I${TARGETFS_DIR}/usr/include/aarch64-linux-gnu”)
set(CMAKE_CXX_FLAGS “${CMAKE_CXX_FLAGS} -I${TARGETFS_DIR}/usr/include -I${TARGETFS_DIR}/usr/include/aarch64-linux-gnu”)

But during the compilation, it’s a bunch of errors like
/l4t/targetfs/usr/include/wchar.h:524:8: error: ‘_Float128’ does not name a type; did you mean ‘_Float32x’?

error: cast from ‘void*’ to ‘uintptr_t’ {aka ‘unsigned int’} loses precision [-fpermissive]
66 | const auto __intptr = reinterpret_cast<uintptr_t>(__ptr);

So, my questions are:

  1. Is my workflow is correct?
  2. What should I do to compile my program successfully? I don’t need any additional libraries here, only Qt (that hopefully was compiled correctly).

*** Please note that this reply is generated by LLM automatically ***

Based on the provided context, I will attempt to answer your questions and provide a comprehensive solution.

Is your workflow correct?

Your workflow seems to be mostly correct. You have:

  1. Downloaded the correct image (nvcr.io/nvidia/jetpack/linux/aarch64/crosscompile/x86_64) for cross-compiling on an x86_64 host for an aarch64 target (Jetson AGX Orin).
  2. Extracted the toolchain and targetfs folders.
  3. Configured and built Qt for the target platform.
  4. Created a CMakeLists.txt file for your project, including Qt libraries and setting up cross-compilation.

However, there might be some issues with the configuration or the compilation process, which I’ll address below.

What should you do to compile your program successfully?

To resolve the compilation errors, follow these steps:

  1. Verify the Qt configuration: Double-check that you have configured Qt correctly for the target platform. Make sure you have set the correct QT_ARCH and QT_TARGET_ARCH variables.
  2. Check the CMakeLists.txt file: Review your CMakeLists.txt file to ensure that you have correctly included the Qt libraries and set up cross-compilation. Pay attention to the CMAKE_SYSROOT and CMAKE_STAGING_PREFIX variables.
  3. Use the correct compiler: Ensure that you are using the correct compiler for the target platform. You can specify the compiler using the CMAKE_C_COMPILER and CMAKE_CXX_COMPILER variables in your CMakeLists.txt file.
  4. Check the include paths: Verify that the include paths for Qt and other dependencies are correctly set. You can use the CMAKE_INCLUDE_PATH variable to specify additional include paths.
  5. Clean and rebuild: Try cleaning your build directory and rebuilding your project from scratch.

Here’s an example of a CMakeLists.txt file that might help you get started:

cmake_minimum_required(VERSION 3.10)
project(MyProject)

# Set the Qt architecture and target architecture
set(QT_ARCH "aarch64")
set(QT_TARGET_ARCH "aarch64")

# Set the CMake system root and staging prefix
set(CMAKE_SYSROOT "/path/to/targetfs")
set(CMAKE_STAGING_PREFIX "/path/to/staging")

# Set the C compiler and C++ compiler
set(CMAKE_C_COMPILER "/path/to/toolchain/bin/aarch64-linux-gnu-gcc")
set(CMAKE_CXX_COMPILER "/path/to/toolchain/bin/aarch64-linux-gnu-g++")

# Include Qt libraries
find_package(Qt5 COMPONENTS Core Gui Widgets REQUIRED)

# Add your project sources
add_executable(MyProject main.cpp)

# Link against Qt libraries
target_link_libraries(MyProject Qt5::Core Qt5::Gui Qt5::Widgets)

Replace the /path/to/ placeholders with the actual paths to your toolchain, targetfs, and staging directories.

If you’re still experiencing issues, please provide more details about the errors you’re encountering, and I’ll do my best to help you troubleshoot the problem.

*** Please give the thumbs up if you get answers you like. Or provide feedback to help us improve the answer. ***

I can’t be of much help here, but when you see something like the above it makes me wonder if development header files are missing. Are you certain that everything needed for build is in your user space filesystem content?

Something I will suggest is that if you set up the Jetson itself such that you can build the software you want natively on the Jetson, then you can clone the rootfs and use the raw clone on the host PC in loopback mount. That loopback mount can replace any target filesystem, and it is guaranteed to have everything you need and guaranteed to match what the Jetson wants as well.

Raw clones are rather large, but you could put it on an external drive or thumb drive if needed.

Thank you for the quick reply. This seems like a good approach. However, in my case, the issue is that I cannot get direct (and prolonged) access to the Jetson to clone the filesystem. That’s why I was hoping to use a prepared Docker image to compile my program and then just transfer the binary to the target device.

So, I will try this Docker approach. My question: is my overall workflow heading in the right direction?

Do you have ssh and root access? If so, then you can use rsync over ssh (if the connection has enough speed you’d basically just copy the content over ssh). This does not create a partition image for flash, but it does duplicate the exact running filesystem. If not, then something like the ARM emulator (perhaps in combination with Docker) would be the correct direction.