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 )
The process to build a CMake project for QNX can be defined in a few steps:
CMakeLists.txt to build the application.qnxToolchain.cmake to set the path to the QNX compilers and libraries for the target device.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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With