Hi,
I would like to use the C++ API for a RTOS (QNX). I’m using cmake 3.10.2 for the cross compilation.
To make the cross compilation possible I use a toolchain file that looks like this:
SET(CMAKE_SYSTEM_PROCESSOR "x86_64")
SET(CMAKE_SYSTEM_NAME QNX)

IF(CMAKE_HOST_LINUX)
  SET(HOST_EXECUTABLE_SUFFIX "")
ENDIF(CMAKE_HOST_LINUX)

FIND_PATH(QNX_HOST
  NAME usr/bin/qcc${HOST_EXECUTABLE_SUFFIX}
  PATHS $ENV{QNX_HOST}
  NO_CMAKE_PATH
  NO_CMAKE_ENVIRONMENT_PATH
)
  
FIND_PATH(QNX_TARGET
  NAME usr/include/errno.h
  PATHS $ENV{QNX_TARGET}
  NO_CMAKE_PATH
  NO_CMAKE_ENVIRONMENT_PATH
)

IF(CMAKE_HOST_LINUX)
  FIND_PATH(QNX_CONFIGURATION
    NAME /etc/qnx/bin/qnxactivate
    PATHS $ENV{QNX_CONFIGURATION}
    "$ENV{QNX_HOST}/usr/bin/qconfig"
    NO_CMAKE_PATH
    NO_CMAKE_ENVIRONMENT_PATH
 )
ENDIF(CMAKE_HOST_LINUX)

SET(ENV{QNX_HOST} ${QNX_HOST})
SET(ENV{QNX_TARGET} ${QNX_TARGET})
IF(CMAKE_HOST_LINUX)
  SET(ENV{QNX_CONFIGURATION} ${QNX_CONFIGURATION})
  SET(ENV{PATH} "$ENV{PATH};${QNX_HOST}/usr/bin")
ENDIF(CMAKE_HOST_LINUX)

SET(CMAKE_MAKE_PROGRAM "${QNX_HOST}/usr/bin/make${HOST_EXECUTABLE_SUFFIX}"    CACHE PATH "QNX Make Program")
SET(CMAKE_SH           "${QNX_HOST}/usr/bin/ksh${HOST_EXECUTABLE_SUFFIX}"      CACHE PATH "QNX shell Program")
SET(CMAKE_AR           "${QNX_HOST}/usr/bin/nto${CMAKE_SYSTEM_PROCESSOR}-ar${HOST_EXECUTABLE_SUFFIX}"      CACHE PATH "QNX ar Program")
SET(CMAKE_RANLIB       "${QNX_HOST}/usr/bin/nto${CMAKE_SYSTEM_PROCESSOR}-ranlib${HOST_EXECUTABLE_SUFFIX}"      CACHE PATH "QNX ranlib Program")
SET(CMAKE_NM           "${QNX_HOST}/usr/bin/nto${CMAKE_SYSTEM_PROCESSOR}-nm${HOST_EXECUTABLE_SUFFIX}"      CACHE PATH "QNX nm Program")
SET(CMAKE_OBJCOPY      "${QNX_HOST}/usr/bin/nto${CMAKE_SYSTEM_PROCESSOR}-objcopy${HOST_EXECUTABLE_SUFFIX}" CACHE PATH "QNX objcopy Program")
SET(CMAKE_OBJDUMP      "${QNX_HOST}/usr/bin/nto${CMAKE_SYSTEM_PROCESSOR}-objdump${HOST_EXECUTABLE_SUFFIX}" CACHE PATH "QNX objdump Program")
SET(CMAKE_LINKER       "${QNX_HOST}/usr/bin/nto${CMAKE_SYSTEM_PROCESSOR}-ld"     CACHE PATH "QNX Linker Program")
SET(CMAKE_STRIP        "${QNX_HOST}/usr/bin/nto${CMAKE_SYSTEM_PROCESSOR}-strip${HOST_EXECUTABLE_SUFFIX}"   CACHE PATH "QNX Strip Program")

SET(CMAKE_C_COMPILER ${QNX_HOST}/usr/bin/nto${CMAKE_SYSTEM_PROCESSOR}-gcc${HOST_EXECUTABLE_SUFFIX})
SET(CMAKE_C_FLAGS_DEBUG "-g")
SET(CMAKE_C_FLAGS_MINSIZEREL "-Os -DNDEBUG")
SET(CMAKE_C_FLAGS_RELEASE "-O3 -DNDEBUG")
SET(CMAKE_C_FLAGS_RELWITHDEBINFO "-O2 -g")

SET(CMAKE_CXX_COMPILER ${QNX_HOST}/usr/bin/nto${CMAKE_SYSTEM_PROCESSOR}-c++${HOST_EXECUTABLE_SUFFIX})
SET(CMAKE_CXX_FLAGS_DEBUG "-g")
SET(CMAKE_CXX_FLAGS_MINSIZEREL "-Os -DNDEBUG")
SET(CMAKE_CXX_FLAGS_RELEASE "-O3 -DNDEBUG")
SET(CMAKE_CXX_FLAGS_RELWITHDEBINFO "-O2 -g")

SET(CMAKE_FIND_ROOT_PATH ${QNX_TARGET}) 
SET(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
SET(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
SET(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)

If I compile a program without Pytorch everything works fine. But when I customize the CMakeLists.txt for Pytorch I get an error message when I run the following cmake command:
cmake -DCMAKE_TOOLCHAIN_FILE=../cmake/qnx_7.0.0_linux_x86_64.cmake ..
-- The C compiler identification is GNU 5.4.0
-- The CXX compiler identification is GNU 5.4.0
-- Check for working C compiler: /home/marcel/qnx700/host/linux/x86_64/usr/bin/ntox86_64-gcc
-- Check for working C compiler: /home/marcel/qnx700/host/linux/x86_64/usr/bin/ntox86_64-gcc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /home/marcel/qnx700/host/linux/x86_64/usr/bin/ntox86_64-c++
-- Check for working CXX compiler: /home/marcel/qnx700/host/linux/x86_64/usr/bin/ntox86_64-c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Looking for pthread.h
-- Looking for pthread.h - found
-- Looking for pthread_create
-- Looking for pthread_create - found
-- Found Threads: TRUE  
-- Could NOT find torch (missing: TORCH_LIBRARY) 
CMake Error: The following variables are used in this project, but they are set to NOTFOUND.
Please set them or make sure they are set and tested correctly in the CMake files:
torch;torch_library;C10_LIBRARY
    linked by target "owndataset_tsp" in directory /home/marcel/Documents/pytroch_cpp_owndataset_tsp

-- Configuring incomplete, errors occurred!
See also "/home/marcel/Documents/pytroch_cpp_owndataset_tsp/build/CMakeFiles/CMakeOutput.log".

My CMakeLists.txt File looks like this:
cmake_minimum_required(VERSION 3.0.0 FATAL_ERROR)

project(pytorch_cpp_owndataset)

list(APPEND CMAKE_PREFIX_PATH "/home/marcel/Documents/libs/libtorch1.5linux/libtorch")
set(CMAKE_MODULE_PATH "/home/marcel/Documents/libs/libtorch1.5linux/libtorch/share/cmake/Torch")

find_package(Torch REQUIRED)

if ("${CMAKE_SYSTEM_NAME}" STREQUAL QNX)
	set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=gnu++14")
endif()

include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include)

link_directories(${CMAKE_BINARY_DIR}/bin)
set(EXECUTABLE_OUTPUT_PATH ${CMAKE_BINARY_DIR}/bin)

set(EXECUTABLE_NAME owndataset_tsp)

add_executable(${EXECUTABLE_NAME} main.cpp src/csv2vector.cpp src/owndata.cpp)

target_link_libraries(${EXECUTABLE_NAME} "${TORCH_LIBRARIES}")
set_property(TARGET ${EXECUTABLE_NAME} PROPERTY CXX_STANDARD 14)

I can’t explain why cmake can’t find the torch library. The path is correctly set in the CMakeLists.txt. Because if I run cmake without the toolchain file and compile for my host machine everything works.
I hope someone can help me with that.
Here is the CMakeOutput.log:

  
      gist.github.com
  
  
    https://gist.github.com/shyney7/02c1d6cb5ce9418b7bb8df2817cbf024 13
CMakeOutput.log
The target system is: QNX -  - x86_64
The host system is: Linux - 5.3.0-51-generic - x86_64
Compiling the C compiler identification source file "CMakeCCompilerId.c" succeeded.
Compiler: /home/marcel/qnx700/host/linux/x86_64/usr/bin/ntox86_64-gcc 
Build flags: 
Id flags:  

The output was:
0

This file has been truncated. show original