q++, qcc
Compile command (QNX)
Syntax:
For C:
qcc [options] [operands]
For C++:
q++ [options] [operands]
Runs on:
Linux, Microsoft Windows
Options:
- -A library[.a]
- Build a new archive.
- -a library[.a]
- Add to the given archive.
- -bootstrap
- Link statically and use the $QNX_TARGET/processor/lib/nto.link script for executables that are included in a boot image's bootstrap section. Use this option only in the linker command specification for mkifs.
- -Bdynamic
- Link dynamically against any subsequent libraries on the command line; see
Linking against static and dynamic libraries,
below. - -Bstatic
- Link statically against any subsequent libraries on the command line; see
Linking against static and dynamic libraries,
below. - -C
- Preprocessor leaves comments.
- -c
- Compile only.
- -D name[=value]
- Define the symbol name, optionally setting its value.
- -E
- Preprocess to stdout.
- -EB or -EL
- Compile for big or little endian.
- -g
- Compile with debug.
- -I path[:path ...]
- Set the search path for
#include
directives. - -isystem path[:path ...]
- Set the search path for
#include
directives. This option is similar to -I, but the directories given in the -isystem option are searched after those specified with -I, but before the standard system directories. The -isystem option is intended to be used for vendor-supplied system header files. - -L path[:path ...]
- Set the library search path.Note:The development tools have been designed to work out of their processor directories (x86_64, etc.). This means you can use the same tool set for any target platform.
If you have development libraries for a certain platform, put them into the platform-specific library directory (e.g., /x86_64/lib), which is where the compiler tools look by default. Don't put the libraries in /lib or /usr/lib, which are ignored. Alternatively, use the -L option to specify the libraries' location.
- -l library
- (
el
) Add library to the list of libraries to link against. This option has the following forms:- -l:filename — link against the exact file specified.
- -lshort_name — search for a library
named libshort_name.so;
if that file can't be found, link against
libshort_name.a. Omit
the
lib
prefix and any extension from the library's name. For example, to link against libsocket, specify -l socket.
You can specify more than one -l option. For more information, see
Linking against static and dynamic libraries,
below. - -lang-c
- Treat as C (the default for qcc).
- -lang-c++
- Treat as C++ (the default for q++).Note:You need to link C++ programs with the -lang-c++ option in order for exceptions to work.
- -M
- Generate a mapfile called output_file.map.
- -N stacksize[K]
- Specify the stack size, in bytes or kilobytes. When this option is specified, qcc configures the process's main thread to use the specified stack size, which will be rounded up to a multiple of the pagesize (4K).
- -n
- Don't execute.
- -nodefaultlibs
- Don't use the
ld_stdlib
section. - -nopie
- Compile the executable without Position-Independent Executable (PIE) support (i.e., without the -pie option).
- -nopipe
- Use temporary files rather than pipes between phases.
- -nostartup
- Don't use
ld_startup_*
sections. - -nostdinc
- Don't include the standard C include paths.
- -nostdinc++
- Don't include the standard C++ include paths.
- -nostdlib
- Don't use the
ld_startup_*
orld_stdlib
sections. - -nostdlib++
- Don't use the
ld_stdlib++
section. - -O[level]
- (
Oh
) Do compile-phase optimization. For information about the levels, see the documentation for gcc at https://gcc.gnu.org/onlinedocs/. - -o outfile
- Specify the name of the output file. The default is a.out.Note:Note that the make utility, when used with the default settings, produces an output file with the same name as the input file. For example:
make file1
results in the executable output file file1.
- -P
- Preprocess to file.i (C) or file.ii (C++).
- -pie
- Compile the executable with PIE support. This is the default behavior.
- -print-prog-name=tool_name
- Print the full absolute name of the specified tool used by qcc or
q++. Supported values are:
- ar — archiving tool
- as — assembler
- cc1 — C compiler
- cc1plus — C++ compiler
- cpp — C preprocessor
- ld — linker
- -S
- Compile, leave assembly in file.s.
- -save-temps
- Save intermediate files created during compilation.
- -set-default
- Set the current -V argument as the default target. For example:
qcc -V12.0,gcc_ntoaarch64le -set-default
sets GCC 12.x for AArch64 little-endian as the default.
Note:This option is intended for use at the command line, not for makefiles. - -shared
- When compiling, make the object position-independent so that it's suitable for inclusion in a shared object. When linking, combine the modules into a shared object.
- -static
- Link against static libraries only; see
Linking against static and dynamic libraries,
below. - -std=language
- Specify the language standard. We currently support c11, iso9899:2011,
c++11, c++14, c++17, and c++20. For more
information, see
Options Controlling C Dialect
in the gcc documentation at https://gcc.gnu.org/onlinedocs/.Note:This option restricts the language libraries (libc, libc++) to the specified ISO standard, which hides any function calls and symbols that aren't part of that standard. To include everything that's defined in the header files, such as functions that are part of the POSIX standard, also use the -D option to define _QNX_SOURCE. SeeConforming to standards
in theCompiling and Debugging
chapter of the QNX OS Programmer's Guide.There are additional variants of this option that enable vendor-specific compiler extensions: gnu99, gnu11, gnu++98, gnu++11, gnu++14, and gnu++17. If you use these variants, _QNX_SOURCE is defined automatically, and some other non-standard functionality of the compiler is enabled; see the gcc documentation. If you don't specify the -std, the defaults are gnu17 (for C) and gnu++17 (for C++). The libm function calls have runtime semantics of C11, irrespective of the value of -std.
- -stdlib=library
- Select the C++ library type to use. This option maps to the -Y option as
follows:
-stdlib= -Y Library libc++ _cxx LLVM C++ libstdc++ _gpp GNU C++ For more information, see the -Y option below.
- -U name
- Undefine the given symbol.
- -V [[compiler/]version,][target]
- The compiler name, version number, and the target name. If you don't specify -V
at all, qcc uses the default compiler, version, and target.
If you specify the target, qcc looks for the target configuration files in the following paths, according to how compiler, version, and target are specified:
If you specify: qcc looks here: -Vtarget ${QCC_CONF_PATH}/compiler/version (where compiler is inferred from target, and version is the default). -Vversion,target ${QCC_CONF_PATH}/compiler/version (where compiler is inferred from target; if that path doesn't exist, or if version contains a slash [/], then ${QCC_CONF_PATH}/version is used). -Vcompiler,target ${QCC_CONF_PATH}/compiler/version (where version is the specified compiler's default version). -Vcompiler/version,target ${QCC_CONF_PATH}/compiler/version For example, this command:qcc -Vgcc,
lists all targets in all versions of gcc. See the Examples section below for more examples.
The targets include:gcc_ntoaarch64le
gcc_ntoaarch64le_cxx
gcc_ntoaarch64le_gpp
gcc_ntox86_64
(default)gcc_ntox86_64_cxx
gcc_ntox86_64_gpp
For a list of supported targets, specify -V (or -Vcompiler, or -Vcompiler/version, or -Vversion, provided there's a valid ${QCC_CONF_PATH}/version directory).
- --version
- Display the version number and print the default toolchain.
- -v[v]
- Operate verbosely (the second v turns on verbosity in the compiler).
- -W phase,arg[,arg ...]
- Pass the specified option and its arguments through to a specific phase:
- p — preprocessor
- c — compiler
- l — linker
- a — assembler
For example, if you want to pass the -S option to the linker, specify -Wl,-S on the command line for qcc.
Note that -W passes the parameters without modifications, which can result in some unexpected behavior. For example, when passing the -MD option to the preprocessor or compiler using the -W option (i.e.,-Wc, -Wp), you need to specify a filename. This is different from using the -MD option with gcc as gcc will generate a filename if the filename is not provided.
Note:In the case the application cannot be linked due to command line limitations in the system host shell, notably Windows, prefix the linker response file, [the @ file] with a -Wl. This way the qcc will not expand and the command will directly pass onto the linker sub-process. - -w
- Suppress all warnings.Note:If you specify -w along with multiple warning options, all warnings are suppressed regardless of the order of the options. In other words, -w always wins.
You can use the gcc-style -W* options to control which warnings are displayed.
- -x extension
- Treat the files that follow as being of type extension. The following values
of extension are accepted:
c
c-header
c++
c++-header
cpp-output
assembler
assembler-with-cpp
as well as valid file extensions, such as .c, .cc, .cpp, .C, .i, .ii, .s, and .S.
Use -xnone to go back to normal suffix typing. For example, to compile myfile.h as if it were a .c file:qcc -xc myfile.h
- -Y lib_type
- Select the C++ library type to be used (if available); lib_type can be:
_cxx
— LLVM C++ library (default)_gpp
— GNU C++ library
There aren't any no-exceptions variants of the LLVM and GNU C++ libraries; add -fno-exceptions to CXXFLAGS.
Note:Even with exceptions disabled, the new() operator throws astd::bad_alloc
exception if there isn't enough memory. If you want new() to return NULL instead of throwing an exception, you can provide a custom new handler via std::set_new_handler() to do so, or usestd::nothrow
.
Description:
The q++ and qcc utilities are the QNX compiler interfaces. By default, q++ considers a program to be C++, while qcc considers it to be C.
Suffix | File type | Parser |
---|---|---|
.s | Assembly language | Assembler |
.S | Assembly language with preprocessor directives | Assembler |
.c | C or C++ code | C or C++ compiler, depending on whether you invoke qcc or q++ |
.i | Preprocessed C or C++ code | C or C++ compiler, depending on whether you invoke qcc or q++ |
.C, .cc, .cpp | C or C++ code | C or C++ compiler, depending on whether you invoke qcc or q++ |
.H, .HPP, .h++, .h, .hh, .hpp, .hxx | Precompiled header | C or C++ compiler, depending on whether you invoke qcc or q++ |
.ii | Preprocessed C++ code | C or C++ compiler, depending on whether you invoke qcc or q++ |
.o | Object file | Linker |
.a | Library file | Linker |
These utilities don't allow multiple options to be specified after a dash character (-). For example, -gc isn't valid; you must specify -g -c instead. Operands (source and object files) and options may be mixed and specified in any order. Some options, such as -I and -L, are order-dependent—the order in which they appear in the command line determines the order of the searches made. All command-line arguments are processed before any compilation or linking begins.
When qcc encounters a compilation error that stops an object file from being created, it writes a diagnostic to the standard error and continues to compile other source files, but it bypasses the link phase and returns a nonzero exit status. If the link phase is entered and is unsuccessful, a diagnostic is written and qcc exits with a nonzero status.
The -c option suppresses the link phase. If you have many separate source files that you must update and modify individually, you'll probably use the -c option frequently.
You may occasionally wish to examine the assembly code produced by the code generator. The -S option produces an assembly file ending in .s.
If you need to specify a parameter to any of the language processors, you may use the -W c,option. Check the documentation on each processor to determine its options.
The compiler defines various preprocessor symbols (or manifest constants) that can help you make decisions at compile time. For more information, see the Manifests chapter of the QNX OS C Library Reference.
Handling other options
When processing command-line options, qcc passes any options beginning with the sequence -m or -f (except -flto) directly to the compiler, including the preprocessor, unmodified. Any argument beginning with the sequence -H or -B (except -Bstatic or -Bdynamic) is passed to the compiler (but not the preprocessor) unmodified.
This is also true of any command-line option beginning with the sequence -W, except for those containing a comma. In the latter case, the option must be of the form matching the regular expression -W[aclp],.* in which the tail of the expression (after the comma) is passed through to the assembler, compiler, linker, and preprocessor (compiler) respectively.
All other options are either processed directly by qcc in some way or rejected with a diagnostic message.
So, passing -fno-builtin for example has the same effect as passing -Wc,-fno-builtin in our current GCC-based toolchain.
Linking against static and dynamic libraries
The -Bdynamic, -Bstatic, -l, and -static options work together as follows:
- The -l:filename option (with a colon) tells the linker to link against the exact file specified.
- The -lshort_name option (without a colon) tells the linker to search for a file called libshort_name.so; if that file can't be found, link against libshort_name.a.
- The -Bstatic and -Bdynamic options are position-dependent and tell the linker whether or not to search for the .so version of libraries specified without a colon that appear after the -B option on the command line.
- The -static option tries to create an executable with static addresses (i.e., like -nopie), which means that it needs to use as many S.a libraries as possible.
- The qcc utility automatically links against some default libraries, including libc. If the last -Bstatic option on the command line appears after the last -Bdynamic option, qcc links against the static versions of the default libraries. If this isn't what you want, simply add -Bdynamic after the list of libraries on the command line.
- If you
use the standard filesystem library (
std::filesystem
), you need to explicitly link in libc++fs.a. In other words, if your C++ code contains#include <filesystem>
, then your linker line should contain -lc++fs. This is unlike other parts of the C++ standard library where the implementations are pulled in automatically by the q++ compiler.
License checking
The q++ and qcc utilities check for a valid QNX license key before performing any operation. If the license check fails, the utility stops running and displays a diagnostic message. A license check may fail if the license key is expired, missing, or not currently activated, or if the key doesn’t contain the permissions needed to run the utility.
Examples:
qcc -Vgcc_ntox86_64 myfile.c
qcc -Vgcc_ntox86_64 -o myfile myfile.c
qcc -o myfile myfile.c
qcc -Vgcc_ntoaarch64le -o myfile myfile.c
qcc -V12.0,gcc_ntoaarch64le -o myfile myfile.c
make myfile
qcc -Vgcc_ntox86_64 -shared -c shared.c
qcc -Vgcc_ntox86_64 -shared -o libshared.so shared.o
Files:
- a.out
- The default output file. You can use the -o option to override this.
- Configuration files:
- ${QCC_CONF_PATH}/version/*.conf, ${QCC_CONF_PATH}/default, ${QCC_CONF_PATH}/gcc/default, ${QCC_CONF_PATH}/gcc/version/default
Environment variables:
- QCC_CONF_PATH
- The name of the directory that contains the configuration files. The default directory is ${QNX_HOST}/etc/qcc.
Exit status:
- 0
- Success.
- >0
- An error occurred.
- 129
- License not found.
- 130
- Product is not covered under your license.
- 131
- License expired.
- 132
- License not activated.
- 133
- Can't connect to the license server.