Make

Make has built-in rules which depend on variables. You need to set a few variables in the Makefile to instruct Make what to do:

CC=qcc
CXX=q++
TARGET_ARCH=-Vgcc_ntoaarch64le

Alternatively, you can set those variables on the command line, for example:

source ~/qnx800/qnxsdp-env.sh
CXX=q++ TARGET_ARCH=-Vgcc_ntoaarch64le make hello

The above command cross compiles hello.cpp for the QNX target with aarch64 little endian architecture.

Since qcc and q++ take care of passing system paths to the compiler and linker, you don't need to set the CPPFLAGS and LDFLAGS variables.

If the code uses regular expressions or sockets, you need to modify the LDLIBS variable to inform the linker. Append compiler flags to the CFLAGS (for C code) or CXXFLAGS (for C++ code) variables if you want to instrument your code.

Example Makefile for compiling sockettest.cpp with enabled function instrumentation:

CXX = q++
TARGET_ARCH = -Vgcc_ntoaarch64le
CXXFLAGS += -g -O0 -finstrument-functions
LDLIBS += -lsocket -lprofilingS

all: sockettest

Project developers usually follow Makefile conventions, which allow users to customize the build.

Developers should assume that users can override certain variables, such as CFLAGS. If there are C compiler options that are required for proper compilation, they should not be included in CFLAGS, but instead, the compilation command should be modified directly.

On the other hand, as long as the project developers adhere to conventions, users can safely overwrite such variables when porting projects to QNX.

Many Makefiles define an install target with commands that copy generated files to specific locations on the host.

This approach isn't applicable for cross compiled projects. Instead, QNX aims to copy the binaries to a staging folder or the QNX SDP location, making them available for other projects.

You may consider using the DESTDIR variable in combination with other variables, such as bindir and libdir, as the destination:

install:
    $(INSTALL_PROGRAM) foo $(DESTDIR)$(bindir)/foo
    $(INSTALL_DATA) libfoo.a $(DESTDIR)$(libdir)/libfoo.a

The user can invoke the following commands to install in the staging area:

make DESTDIR=/tmp/stage install

or in SDP:

make DESTDIR=$QNX_TARGET/aarch64le install
Page updated: