2

I am trying to use cmake to build a very simple app with QNX toolchain. I can build it with qcc command line without any problem, but if I using cmake, it always show this error. Does anyone know how to solve it? Thanks!

QNX SDK: v7.1 cmake: v3.21.1

[ 50%] Building CXX object CMakeFiles/hello.dir/src/testhello.cpp.o
cc: Can't specify -P, -C, -E, -c or -S with -o and have multiple files
CMakeFiles/hello.dir/build.make:75: recipe for target 'CMakeFiles/hello.dir/src/testhello.cpp.o' failed
make[2]: *** [CMakeFiles/hello.dir/src/testhello.cpp.o] Error 1
CMakeFiles/Makefile2:82: recipe for target 'CMakeFiles/hello.dir/all' failed
make[1]: *** [CMakeFiles/hello.dir/all] Error 2
Makefile:90: recipe for target 'all' failed
make: *** [all] Error 2

The link is the cmake manual related to QNX https://cmake.org/cmake/help/latest/manual/cmake-toolchains.7.html#id16

I also try cmake in qnx supported?? Porting from Linux to QNX but doesn't work, too

cmake_minimum_required(VERSION 3.14)

project(test)

set(CMAKE_SYSTEM_NAME QNX)

set(arch gcc_ntoaarch64le_gpp)
set(ntoarch aarch64le)
set(QNX_PROCESSOR aarch64le)

set(CMAKE_C_COMPILER qcc)
set(CMAKE_C_COMPILER_TARGET ${arch})
set(CMAKE_CXX_COMPILER q++)
set(CMAKE_CXX_COMPILER_TARGET ${arch})

#set(CMAKE_SYSROOT $ENV{QNX_TARGET})

add_executable ( hello src/testhello.cpp )
Rigel Chen
  • 861
  • 7
  • 14
  • 2
    The [referenced answer](https://stackoverflow.com/a/57891777/3440745) describes a **toolchain**. In CMake toolchain - is a **separate file**, not a part of `CMakeLists.txt`. See e.g. [documentation](https://cmake.org/cmake/help/latest/manual/cmake-toolchains.7.html#cross-compiling). – Tsyvarev Nov 12 '21 at 16:29
  • this seems like an error related to compiler flags "_cc: Can't specify -P, -C, -E, -c or -S with -o and have multiple files_". Can you show us your compiler flags and how you set them? one way is to export a [compile commands json file](https://stackoverflow.com/a/38040375/11107541). – starball Sep 16 '22 at 03:57

1 Answers1

0

The process to build a CMake project for QNX can be defined in a few steps:

  • Define a CMakeLists.txt to build the application.
  • Define a qnxToolchain.cmake to set the path to the QNX compilers and libraries for the target device.
  • Before the application is build, remember to source the standard QNX toolchain script to initialize important environment variables, then invoke cmake and pass this new toolchain file in the CMAKE_TOOLCHAIN_FILE parameter.

CMakeLists.txt:

cmake_minimum_required(VERSION 3.5)

project(hello_world LANGUAGES CXX)

add_executable(hello_world main.cpp hello.cpp hello.h)

install(TARGETS hello_world LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR})

qnxToolchain.cmake:

SET(CMAKE_SYSTEM_NAME QNX)
SET(CMAKE_C_COMPILER   /Users/Admin/qnx700/host/darwin/x86_64/usr/bin/aarch64-unknown-nto-qnx7.0.0-gcc)
SET(CMAKE_CXX_COMPILER /Users/Admin/qnx700/host/darwin/x86_64/usr/bin/aarch64-unknown-nto-qnx7.0.0-g++)
SET(CMAKE_AR "/Users/Admin/qnx700/host/darwin/x86_64/usr/bin/ntoaarch64-ar" CACHE PATH "QNX AR Program" )
SET(CMAKE_FIND_ROOT_PATH  /Users/Admin/qnx700/target/qnx7)

SET(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
SET(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
SET(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)

Then, to build it for QNX run:

cd helloWorld
mkdir qnxBuild
cd qnxBuild

source ~/qnx700/qnxsdp-env.sh
cmake -G "Unix Makefiles" -DCMAKE_TOOLCHAIN_FILE=../qnxToolchain.cmake ../
make

Note: keep in mind that the exact paths and QNX compilers you'll need depend on where the QNX toolchain has been installed on your system and which operating system you are using. In this example, I was on MacOS trying to build a "Hello World!" application for QNX.

karlphillip
  • 92,053
  • 36
  • 243
  • 426