No build system
The QNX documentation in the "Cross-development" section of the Programmer's Guide explains how to instruct the compiler to cross compile source code for a specific architecture.
For simple projects without a build system, you can call the compiler directly (assuming your SDP path is ~/qnx800) to cross compile for the QNX target with aarch64 little endian architecture:
source ~/qnx800/qnxsdp-env.sh
# for C code
qcc -V gcc_ntoaarch64le hello.c -o hello
# or for C++ code
q++ -V gcc_ntoaarch64le hello.cpp -o hello
Execute qcc -V
to see all supported architectures.
If you've ever worked with GNU compilers, you've probably noticed the
similarity to the gcc
and g++
front-end names.
Many command-line parameters that qcc
and q++
offer are the same, but there
are also some differences. For more details on the qcc
and q++
commands, visit the "`q++, qcc" page in the C Library Reference.
QNX is a POSIX-compliant OS, and you can control POSIX compatibility using feature-test macros at compile time.
C/C++ code can use the manifests for compile-time changes or inspection.
Passing the -vv
option to qcc
and q++
enables verbosity in the compiler,
allowing you to see what's happening under the hood.
For example, the paths to the QNX system header files is passed to the
C++ compiler using the -isystem
option, so you don't need to worry about
specifying them yourself
(the same applies to the paths for the QNX system libraries, which are
passed to the linker using the -L
option).
In other systems, the libc library usually includes support for sockets and regular expressions. However, in QNX, it doesn't. If the code uses regular expressions, you need to explicitly link the libregex.so library. Similarly, if the code uses sockets, you must link the libsocket.so library.
Example of compiling C++ code that uses sockets:
q++ -V gcc_ntoaarch64le hello.cpp -l socket -o hello
If you intend to inspect the project using Momentics IDE, you may want to instrument the code. Visit "Adding debug symbols and instrumentation code to binaries" in the QNX Momentics IDE User's Guide for information related to debugging, code coverage, profiling, etc.
Example of compiling C++ code with enabled function instrumentation for system profiling:
q++ -V gcc_ntoaarch64le -g -O0 -finstrument-functions hello.cpp -l
socket -l profilingS -o hello