Cross compiling error - backtrace

Hardware Platform: DRIVE AGX Pegasus™ Developer Kit
Software Version: DRIVE Software 10
Host Machine Version: native Ubuntu 18.04
SDK Manager Version: 1.0.1.5538

Hello,
I’m trying to cross compile my app using the provided rootfs from the SDK, but I’m getting this error:

CMake Error at /usr/local/share/cmake-3.15/Modules/FindPackageHandleStandardArgs.cmake:137 (message):
  Could NOT find Backtrace (missing: Backtrace_INCLUDE_DIR)
Call Stack (most recent call first):
  /usr/local/share/cmake-3.15/Modules/FindPackageHandleStandardArgs.cmake:378 (_FPHSA_FAILURE_MESSAGE)
  /usr/local/share/cmake-3.15/Modules/FindBacktrace.cmake:90 (find_package_handle_standard_args)
  shared/common/third_party/g3log/Build.cmake:95 (FIND_PACKAGE)
  shared/common/third_party/g3log/CMakeLists.txt:141 (INCLUDE)

But I’m able to find backtrace’s library and include file in the rootfs.

Also, when compiling directly on the Pegasus, it works fine.

What am I missing?

Dear @eladg1,
It is not clear what you are trying to cross compile? is it DW/TensorRT/CUDA or something else?

I’m sorry, you’re right.

I’m trying to compile a small sample file, that outputs the current backtrace.

This is the CMakeLists.txt file:

cmake_minimum_required(VERSION 3.15)

project(Backtrace_Sample)
set(CMAKE_CXX_STANDARD 17)

find_package(Backtrace REQUIRED)

add_executable(backtrace_sample main.cpp)

And this is the source code:

#include <execinfo.h>
#include <stdio.h>
#include <stdlib.h>
/* Obtain a backtrace and print it to stdout. */
void
print_trace (void)
{
  void *array[10];
  char **strings;
  int size, i;
  size = backtrace (array, 10);
  strings = backtrace_symbols (array, size);
  if (strings != NULL)
  {
    printf ("Obtained %d stack frames.\n", size);
    for (i = 0; i < size; i++)
      printf ("%s\n", strings[i]);
  }
  free (strings);
}
/* A dummy function to make the backtrace more interesting. */
void
dummy_function (void)
{
  print_trace ();
}
int
main (void)
{
  dummy_function ();
  return 0;
}

Hi @eladg1,
please try following my steps to successfully build and run your test:
on host:

  1. create main.cpp (or any file name you want) with the mentioned code content
  2. execute:
    ~/nvidia/nvidia_sdk/DRIVE_Software_10.0_Linux_OS_DDPX/DRIVEOS/toolchains/gcc-linaro-7.3.1-2018.05-x86_64_aarch64-linux-gnu/bin/aarch64-linux-gnu-g++ main.cpp -o test
  3. copy test executable to DDPX platform (for example XavierA) using ssh:
    scp test nvidia@<XavierA IP>:~/

on target:(Xavier A)

  1. execute:
    ./test

the output is:
Obtained 5 stack frames.
./test() [0x400780]
./test() [0x40080c]
./test() [0x400824]
/lib/aarch64-linux-gnu/libc.so.6(__libc_start_main+0xe0) [0x7fa5fa26e0]
./test() [0x400698]

please try and figure out what is different in your cmake file that differs from this example.
I suggest you start by looking for how to set the cross-compiler location (gnu compiler mentioned above)

I know exactly what causes the problem to occur. It’s because I’m using find_package(Backtrace REQUIRED) in my cmake file. Running the same cmake w/o this line compiles just fine.
But the strange thing is, when compiling with this line in the cmake on the pegasus, it succeeds to compile.

Hi @eladg1,

the reason for that is that CMake searches for libraries and includes in the build system sysroot only - meaning in the host sysroot when crosscompiling (so libraries for cross-compiling will not be found) and in the pegasus sysroot when native compiling.

you might want to try using Find<package>.cmake file located within your project and use it by using

list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake")

where cmake is usually the name of the folder we set to have all the user-defined package finders.
you will find the include file execinfo.h for the PEGASUS in here:
~/nvidia/nvidia_sdk/DRIVE_Software_10.0_Linux_OS_DDPX/DRIVEOS/drive-t186ref-linux/targetfs_a/usr/include

good luck :)