Updated: October 28, 2024 |
Compile command (QNX)
For C:
qcc [options] [operands]
For C++:
q++ [options] [operands]
Linux, Mac, Microsoft Windows
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.
You can specify more than one -l option. For more information, see Linking against static and dynamic libraries, below.
If you want to set the stack size but pre-allocate the stack instead of using lazy allocation, use elfnote with the -S option.
make file1
results in the executable output file file1.
qcc -V8.3.0,gcc_ntoarmv7le -set-default
will set GCC 8.3.0 for ARMv7 little-endian as the default.
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 gnu11 and gnu++14 for C and C++, respectively.
-stdlib= | -Y | Library |
---|---|---|
libc++ | _cxx | LLVM C++ |
libstdc++ | _gpp | GNU C++ |
For more information, see the -Y option below.
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:
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).
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.
You can use the gcc-style -W* options to control which warnings are displayed.
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
There aren't any no-exceptions variants of the LLVM and GNU C++ libraries; add -fno-exceptions to CXXFLAGS.
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.
These utilities take a list of source and object modules on the command line and invoke the appropriate parser to compile each file. Object modules are passed straight through to the linker. The file suffix determines which parser is used, as follows:
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 Neutrino 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:
Profiling
Here's how to profile your application, so you can see where it's spending its time:
make CCOPTS+=-p LDOPTS+=-p
gprof [your_app] | less
For more information, see the GNU documentation for gprof.
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.
Compile myfile.c and create an executable program for QNX Neutrino for an Intel x86_64 machine in the current directory with the name a.out:
qcc -Vgcc_ntox86_64 myfile.c
Compile myfile.c and create an executable program for QNX Neutrino for an Intel x86_64 machine in the current directory with the name myfile:
qcc -Vgcc_ntox86_64 -o myfile myfile.c
Use the default compiler, version, and target:
qcc -o myfile myfile.c
Use the default version of the compiler, and build for an ARM little-endian target:
qcc -Vgcc_ntoarmv7le -o myfile myfile.c
Use the 8.3.0 version of the compiler, and build for an ARMv7 little-endian target:
qcc -V8.3.0,gcc_ntoarmv7le -o myfile myfile.c
Use make to compile myfile.c and create an executable program in the current directory with the name myfile:
make myfile
Make a shared library:
qcc -Vgcc_ntox86_64 -shared -c shared.c qcc -Vgcc_ntox86_64 -shared -o libshared.so shared.o