Skip to content

v4.7.0 build failure for QNX. Patch suggestion #24567

@Arech

Description

@Arech

System Information

OpenCV 4.7.0 (and likely many other versions before that and probably after)
host: Ubuntu20.04
cross-compiling target: QNX710
ntoaarch64-g++ compiler from QNX SDP 710

Detailed description

I was trying to compile OpenCV 4.7.0 for QNX (using vcpkg, but that is only relevant due to my bugreport there microsoft/vcpkg#35209 and their rightful suggestion to bring changes to the upstream first) and it failed due to essentially incompatibility with a few core QNX definitions in a single file modules/core/src/system.cpp.

This little patch solves them:

diff --git a/modules/core/src/system.cpp b/modules/core/src/system.cpp
index 027072a5da..ae7a249b3e 100644
--- a/modules/core/src/system.cpp
+++ b/modules/core/src/system.cpp
@@ -131,11 +131,15 @@ void* allocSingletonNewBuffer(size_t size) { return malloc(size); }
 #include <cstdlib>        // std::abort
 #endif
 
-#if defined __ANDROID__ || defined __unix__ || defined __FreeBSD__ || defined __OpenBSD__ || defined __HAIKU__ || defined __Fuchsia__
+#if defined __ANDROID__ || defined __unix__ || defined __FreeBSD__ || defined __OpenBSD__ || defined __HAIKU__ || defined __Fuchsia__ || defined __QNX__
 #  include <unistd.h>
 #  include <fcntl.h>
 #if defined __QNX__
 #  include <sys/elf.h>
+#  include <sys/auxv.h>
+using Elf64_auxv_t = auxv64_t;
+#  include <elfdefinitions.h>
+constexpr decltype(auto) AT_HWCAP = NT_GNU_HWCAP;
 #else
 #  include <elf.h>
 #endif

A few comments:

  • QNX has __unix__ undefined and it requires it's own __QNX__ macro to be tested instead
  • Elf64_auxv_t data type isn't defined anywhere in QNX SDP 710 files. auxv64_t seems to be a perfect replacement, but I'm not an expert on this.
  • AT_HWCAP value is also never defined for QNX. NT_GNU_HWCAP seems to be the closest semantical equivalent, but I have no sound grounds under this. Someone more familiar with QNX should verify that.

After applying the patch I was able to compile OpenCV 4.7.0 successfully for QNX using these vcpkg port features ["jpeg","png","tiff","ffmpeg"].

Disclaimer: I didn't run OpenCV tests and validated it works as expected using only our own test app, that uses very few OpenCV features. It's possible that the patch only allows code to compile, but it was never actually tested in runtime with our tests.

Steps to reproduce

Try to crosscompile OpenCV from Ubuntu.Focal to QNX with QNX SDP 710 and get compilation errors in modules/core/src/system.cpp.

For the reference:
vcpkg toolchain file:

if (NOT DEFINED ENV{QNX_HOST} OR NOT DEFINED ENV{QNX_TARGET})
    message(FATAL_ERROR "Please set QNX_HOST and QNX_TARGET environment variables by sourcing \"qnxsdp-env.sh\"!")
endif()

set(CMAKE_SYSROOT $ENV{QNX_TARGET})

set(CMAKE_SYSTEM_NAME QNX)
set(CMAKE_SYSTEM_VERSION 710)
set(CMAKE_SYSTEM_PROCESSOR "aarch64")
set(arch nto${CMAKE_SYSTEM_PROCESSOR})

set(CMAKE_AS "$ENV{QNX_HOST}/usr/bin/${arch}-as")
set(CMAKE_AR "$ENV{QNX_HOST}/usr/bin/${arch}-ar")
set(CMAKE_C_COMPILER "$ENV{QNX_HOST}/usr/bin/${arch}-gcc")
set(CMAKE_CXX_COMPILER "$ENV{QNX_HOST}/usr/bin/${arch}-g++")
set(CMAKE_LINKER "$ENV{QNX_HOST}/usr/bin/${arch}-ld")

set(CMAKE_POSITION_INDEPENDENT_CODE ON)
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_EXTENSIONS OFF)

set(CMAKE_C_STANDARD 11)
set(CMAKE_C_EXTENSIONS OFF)

set(CMAKE_C_COMPILER_TARGET "gcc_ntoaarch64le")
set(CMAKE_CXX_COMPILER_TARGET "gcc_ntoaarch64le")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -D_XOPEN_SOURCE=600 -D_POSIX_C_SOURCE=200112L -D_QNX_SOURCE")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fexceptions -D_XOPEN_SOURCE=600 -D_POSIX_C_SOURCE=200112L -D_QNX_SOURCE")

# Set correct triplet for vcpkg
set(VCPKG_TARGET_TRIPLET arm64-qnx)
# Set path for overlay triplets
set(VCPKG_OVERLAY_TRIPLETS "${CMAKE_CURRENT_LIST_DIR}/../vcpkg/triplets")

set(CMAKE_FIND_LIBRARY_PREFIXES "lib")
set(CMAKE_FIND_LIBRARY_SUFFIXES ".so;.a")
set(CMAKE_LIBRARY_PATH "${CMAKE_SYSROOT}/aarch64le/usr/lib;${CMAKE_SYSROOT}/aarch64le/lib;${CMAKE_SYSROOT}/usr/lib")

# uncomment the line below to use QC provided OpenCV 4.3
# set(CMAKE_SYSTEM_PREFIX_PATH "${CMAKE_SYSTEM_PREFIX_PATH};${CMAKE_SYSROOT}/aarch64le/usr/share/OpenCV")

set(CMAKE_FIND_ROOT_PATH "${CMAKE_SYSROOT};${VCPKG_INSTALLED_DIR}")
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)

vcpkg triplet file:

set(VCPKG_TARGET_ARCHITECTURE arm64)
set(VCPKG_CRT_LINKAGE dynamic)
set(VCPKG_LIBRARY_LINKAGE static)

set(VCPKG_CMAKE_SYSTEM_NAME QNX)

set(VCPKG_ENV_PASSTHROUGH PATH QNX_HOST QNX_TARGET)
set(VCPKG_CHAINLOAD_TOOLCHAIN_FILE "${CMAKE_CURRENT_LIST_DIR}/../../toolchains/aarch64-qnx.cmake")

Issue submission checklist

  • I report the issue, it's not a question
  • I checked the problem with documentation, FAQ, open issues, forum.opencv.org, Stack Overflow, etc and have not found any solution
  • I updated to the latest OpenCV version and the issue is still there
  • There is reproducer code and related data files (videos, images, onnx, etc)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions