compile command (UNIX)


Invoke the C compiler:

cc [options] [operands]
c89 [options] [operands]

Invoke the C++ compiler:

CC [options] [operands]


Produce 16-bit object code, using only 8086 instructions. The code runs on the 16- or 32-bit version of QNX.
Produce 16-bit object code, using 286 instructions. The code runs on the 16- or 32-bit version of QNX if QNX is operating on a processor upwardly compatible with the Intel 286.
Produce 32-bit object code, using 386 instructions optimized for Intel 386 instruction timings. The code runs only on the 32-bit version of QNX.
32-bit, using register calling conventions.
32-bit, using stack calling conventions.
Same as -3, but for 486 instruction timings. This is the default. For maximum performance, you should also use the r optimization (see the -O option).
Same as -3, but for Pentium instruction timings. For maximum performance, you should also use the r optimization (see the -O option).
-A library
Combine all object files provided as operands and build this new library. The library filename is given the .lib suffix.
-a library
Combine all object files provided as operands and add them to this existing library. The library filename is assumed to have a .lib suffix.
Search the QNX 2 migration library that corresponds to the specified memory model (see option -m). The QNX 2 migration library provides backwards compatibility for many discontinued functions. The library is searched before the beta and standard libraries.
Search the beta library that corresponds to the specified memory model (see option -m).

The beta libraries are searched before the standard libraries. The beta libraries include updates made since the last formal release of the software and can be updated by modem using the QNX update system.

Suppress the link phase and retain all created object files.
-D name=text
Define name as if by a C language #define directive. If no text is specified, name is defined as 1.
Copy the language source files to the standard output, expanding all preprocessor directives. No compilation is performed. See also option -P.
Force objects into the same directory as source (default is the current working directory).
-f {option}
Pass through to the -f option of wcc.
Produce symbolic information in the object and executable files. This option is necessary to run the symbolic debugger (wd). If -g1 is specified, the optimizer remains enabled for code generation. If -g2 is specified, the optimizer is disabled, resulting in code that is easier to debug. Specifying -g is the same as specifying -g2. The -g3 option is the same as -g2 but also includes symbolic debugging information for unreferenced type names.

The {w|d|c} part of this option specifies the type of debugging output:

  • w - Watcom (the default)
  • d - Dwarf
  • c - CodeView (not applicable for QNX)
-I directory
Change the default search algorithm for header files whose names don't begin with a slash (/) so that the directory named by the directory pathname is searched before the standard path. The standard path is /usr/include. Headers are searched for in the following order:
  1. in the directory of the file with the #include line
  2. in the directories named in the -I option
  3. in /usr/include
Directories named with the -I option are searched in the order specified. If an #include is surrounded by angle brackets ( <> ), the first search isn't done.
Change char default from unsigned to signed.
-L directory
Change the default algorithm (that searches for libraries) to include this directory. Directories are searched in the order they appear on the command line and before the default directory, /usr/lib. You may change this default by setting the environment variable LIBQNX to one or more directories separated by colons.
-l library
(the letter ``el'') Search this library file for any unresolved references during the link phase. Libraries are searched in the order they appear on the command line, and before the default libraries. If the library name doesn't start with a slash (/), a search is made in the following order:
  1. in the current directory
  2. in the directories named in the -L option
  3. in the default directory
If the library name doesn't end with .lib, the compilation-model suffix is appended.
Produce a symbolic map file with the same name as the output file, but with a .map suffix.
Compile the program to conform to the specified memory model:
Option Model16-bit32-bit
mssmall64K code, 64K data4G code, 4G data
mccompact64K code, >64K dataN/A
mmmedium>64K code, 64K dataN/A
mllarge>64K code, >64K dataN/A
mhhuge>64K code, >64K data with objects >64KN/A
mfflatN/A4G code, 4G data

The small memory model is selected by default. For 16-bit applications, libraries are provided for the small, compact, medium, large, and huge memory models.

For 32-bit applications, only small-model libraries are provided and only small-model compiling is supported. However, cc does permit 32-bit small-model object modules to be linked as either small or flat models (flat-model linking is the default).

-N stacksize
Tell the linker to reserve room for a stack of stacksize bytes. Add a suffix of k to specify the stack size in kilobytes. The defaults are:
32-bit flat32k
32-bit small8k
Enable compiler optimizations. If only -O is specified, the default is equivalent to -Oil. You may specify more than one optimization by providing multiple letters together with no space or punctuation (for example, -Oadx).
Relax alias checking. When you specify this option, the code optimizer assumes that, within the same routine, no variable is indexed both directly by name and indirectly by a pointer. This assumption may reduce the size of the code that is generated. The following example helps to illustrate this point:
extern int i;
void rtn( int *pi ) {

    int k;
    for( k = 0; k < 10; ++k ) {
In this example, if i and *pi referenced the same integer object, i would be incremented by 2 each time through the for loop. The pointer reference *pi would be an alias for the variable i. As a result, in binding the variable i to a register, the compiler would have to make sure the ``in-memory'' copy of i was kept up-to-date. It's unlikely this situation would arise, since you probably wouldn't reference the same variable directly by name and indirectly by a pointer. The -Oa option instructs the code generator that such cases don't arise in the module to be compiled. When the generator doesn't have to worry about the alias problem it can produce more efficient code.
Generate non-optimized code sequences. The resulting code is much easier to debug with wd (see the Debugger User's Guide). By default, cc selects -Od if you specify option -g. But if option -g is followed by one of the other -O options, as in:
    cc -g -Os report
the default -Od is overridden.
Expand certain user functions inline. Whether a function is selected for inline expansion depends on its size, as measured by the number of quads the function generates. The number of quads generated corresponds closely to the number of operators used in an expression. Functions that require more than the specified number_of_quads aren't expanded inline (the default number is 20). This optimization is useful when locally referenced functions are small in size.


    cc -Oe dhrystone
    cc -Oe=25 whetstone
Generate traceable stack frames for functions that contain calls or require stack frame setup. For near functions, cc generates the following function prologue sequence:
16-bit compiler32-bit compiler
push BPpush EBP
mov BP, SPmov EBP, ESP
For far functions, cc generates the following function prologue sequence:
16-bit compiler32-bit compiler
inc BP inc EBP
push BP push EBP
mov BP,SP mov EBP,ESP
The BP/EBP value on the stack is odd or even, depending on the code model.
Generate traceable stack frames for all functions, including those that don't contain calls or require stack frame setup. You should find this useful for developing embedded systems (ROM-based applications).

The f+ flag generates prologue sequences in the same way as the f flag.

Generate certain library functions in-line. For a function to be generated in-line, you must include the appropriate header file containing the prototype for the function. These are the functions that can be generated in-line:

ldiv() (32)
lrotl() (32)
lrotr() (32)
strcmp()(16) strcpy()

A (16) indicates that the function is generated inline by the 16-bit compiler only; a (32) indicates that it's generated inline by the 32-bit compiler only.

If you specify -Oi, the macro __INLINE_FUNCTIONS__ is predefined by the compiler.

(lowercase letter ``el'') Perform loop optimizations. This includes moving loop-invariant expressions outside the loops.
Generate inline 80x87 code for math functions such as sin(), cos(), tan(), and so on. If you specify this option, you must ensure that arguments to these functions fall within the range accepted by their corresponding instructions (for example, fsin, fcos) since no check is made at runtime.

If you also specify Ot, the exp() function is generated as well.

Enable reordering of instructions to achieve better performance on pipelined architectures such as the 486 and the Pentium. This option can make debugging a bit more difficult because the assembly language instructions generated for a source statement may be intermixed with instructions generated for surrounding statements.
Favor space over time when generating code. This results in smaller code but possibly slower execution.
Favor time over space when generating code. This results in faster execution but possibly larger code.
Select the -Oi, -Ol, and Wc,-s (no stack overflow checking) options. When you combine -Ox with the -Oa and -Ot options, the code generator attempts to give you the fastest executing code possible.
By default, cc selects a balance between space and time.
-o outfile
Use the pathname outfile instead of the default a.out for the executable file. If the -c option is also specified, outfile is taken to be the name of an object file to create.
Run only the C preprocessor and leave the output in the same name as the source file but with an .i suffix. See also option -E.
Compile more quietly without printing the details of each compiler phase.
Produce assembly-list files ending in .S for all source or object files provided. If an object file is specified, the original source lines won't be included in the generated assembly.
Strip symbolic information that may exist in object files compiled with the -g option. The symbolic information isn't removed from these object files, but the resulting executable file is stripped of all symbolic information.
-T level
Set the privity level of the load file, where level can be a number from 0 to 3 (default is 3). A setting of T 1 is required for programs using in, out, cli, and sti. For more information, see the Description.
-U name
Remove any initial definition of name that the compiler itself might define. This doesn't affect any names defined in included header files.
-v version[@version_file]
Use this version of the compiler. The cc utility looks up the version supplied in the file /etc/default/cc, unless @version_file is specified, in which case the version information is looked up in that file instead. The version file (/etc/default/cc or the file specified) consists of entries that look like:

where the version_string is the version name cc is to recognise, and a directory_path is search path delimited by colons (:), such as ``directory1:directory2''. The ccopts= cc_options is optional. It may be used to specify additional command line parameters to cc that are to be used for that version of the compiler. A typical entry might look like:

-W c,option
Pass the command specified by option to the language processor, as specified by the c argument. The language processor is typically the letter c for the C language. You may specify c as one of the following:
For this processor:specify:
C compilerc
C++ compilerC
disassemblerd (used in conjunction with -S)
preprocessorp (used in conjunction with -E or -P)
SQL preprocessorS

If option contains a space, you must enclose the entire option in double quotes (for example, "-Wc,-xfile1").

The command specified by option is defined by the language processor being used. Please refer to the appropriate documentation.

-w warning_level
Use this warning level. If -w isn't specified, the built-in default for the language processor is used.
Print, but don't execute, the steps required to compile or link.
Use an experimental version of the compiler tools. Each command is invoked with a leading x (for example, wcc would be invoked as xwcc).
Pass through to the -z option of the C or C++ compiler.


Compile test.c and create a 32-bit executable program in the current directory with the name a.out:

    cc test.c

Compile test.c and create a 32-bit executable program in the current directory with the name test:

    cc -o test test.c

Compile test.c and create an executable program in the current directory with the name test. Use the default rules to invoke cc (see the make utility in the QNX Utilities Reference):

    make test

Compile test.c and create a 16-bit object file in the current directory with the name test.o:

    cc -2 -c test.c

Disable stack overflow checking by passing the -s option to the C compiler:

    cc -Wc,-s test.c

Note: For more information on specific compiler options, see the C/C++ Compiler Options chapter of the Compiler & Tools User's Guide.


The cc utility is the QNX compiler interface. It's based on the POSIX c89 utility.

The cc utility takes a list of source and object modules on the command line and invokes 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:

.cC compiler
.C, .cc, .cppC++ compiler
.sqcEmbedded SQL preprocessor

Note: The parser must exist for you to use it. The cc utility was designed to work with potential future parsers and may contain entries for parsers not yet available.

The cc utility doesn't allow multiple options to be specified after a dash character (-). For example, -bc isn't valid; you must specify -b -c instead. Operands (source and object files) and options may be mixed and specified in any order. Some options like -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 cc 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 any file generates warnings or errors, and standard error is a tty (that is, it isn't a pipe), a new file is created with the same name as the input file but with a .err suffix. If the link phase is entered and is unsuccessful, a diagnostic is written and cc 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.

In QNX, a program can run at one of the privity levels in the following table. The -T option lets you set the privity.

0Privity is determined at load time.
1Required for programs using cli, sti, in, out opcodes. Most programs with interrupt handlers fall into this category.
3Used by the vast majority of programs.

With level 0, the privity of the program is automatically set when the program is loaded. If the program is invoked by the superuser, its privity is set to 1; if the program is invoked by a normal user, its privity is set to 3. You should find this feature useful if your program needs to do in/out opcodes only when it is run by a superuser.

If a program is set to privity level 1, any attempt to execute that program by a non-superuser results in denied access.

Although you must be a superuser to execute privity level 1 programs, privity and superuser are two different concepts. The concept of superuser comes from POSIX, while privity relates only to Intel 286, 386, 486, and Pentium processors and allows or disallows a small set of opcodes.

If you link a program under QNX 4.1 (or later), its privity defaults to 3. If you find this program terminates with a SIGSEGV, check to see if it faults on one of the special opcodes that require privity level 1. If so, you should relink using the -T 1 option.

You may occasionally wish to examine the assembly code produced by the code generator. The -S option produces an assembly file ending in .S. You can also take an object file and convert it back to assembly with this option.

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 table below describes how the options for the cc command correspond to those for the Watcom C/C++ compiler and linker:

cc option Compiler option Linker option
0 0
2 2
3 3
3[r,s] 3[r,s]
4 4
4[r,s] 4[r,s]
5 5
5[r,s] 5[r,s]
b LIBRARY beta libraries
B LIBRARY backward compatibility libraries
D name=text d+, dname[=text]
E p
F fo
f{option} f{option}
g{1|2|3}{w|d|c} d{1|2|3}, h{w|d|c} DEBUG ALL
g1{+} d1{+} DEBUG ALL
I directory i=directory
j j
l library LIBRARY library
L directory LIBPATH directory
m{f|s|c|m|l|h} m{f|s|c|m|l|h}
N stacksize OPTION STACK=stacksize
o outfile NAME outfile
O{a,d,i,l,s,t,x} o{a,d,i,l,s,t,x}
P p fo=name.i
U name uname
Wc,option option
w warning_level wwarning_level
z{option} z{option}

Exit status:

Successful completion.
An error occurred.

Environment variables:

The list of library directories to search-directories are separated by colons. If LIBQNX isn't defined, cc uses /usr/lib. If LIBQNX is defined, it's used as is.


The default output file is named a.out. This default may be changed with the -o option.

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.

See also:

lex utility (Lexical analyzer generator), make utility (Maintain, update and regenerate groups of programs), yacc utility (Parser generator), Watcom Compiler & Tools User's Guide