Путеводитель по Руководству Linux

  User  |  Syst  |  Libr  |  Device  |  Files  |  Other  |  Admin  |  Head  |



   c99.1p    ( 1 )

компилировать стандартные программы на C (compile standard C programs)

Примеры (Examples)

1. The following usage example compiles foo.c and creates the
           executable file foo:

c99 -o foo foo.c

The following usage example compiles foo.c and creates the object file foo.o:

c99 -c foo.c

The following usage example compiles foo.c and creates the executable file a.out:

c99 foo.c

The following usage example compiles foo.c, links it with bar.o, and creates the executable file a.out. It may also create and leave foo.o:

c99 foo.c bar.o

2. The following example shows how an application using threads interfaces can test for support of and use a programming environment supporting 32-bit int, long, and pointer types and an off_t type using at least 64 bits:

offbig_env=$(getconf _POSIX_V7_ILP32_OFFBIG) if [ $offbig_env != "-1" ] && [ $offbig_env != "undefined" ] then c99 $(getconf POSIX_V7_ILP32_OFFBIG_CFLAGS) \ $(getconf POSIX_V7_THREADS_CFLAGS) -D_XOPEN_SOURCE=700 \ $(getconf POSIX_V7_ILP32_OFFBIG_LDFLAGS) \ $(getconf POSIX_V7_THREADS_LDFLAGS) foo.c -o foo \ $(getconf POSIX_V7_ILP32_OFFBIG_LIBS) \ -l pthread else echo ILP32_OFFBIG programming environment not supported exit 1 fi

3. The following examples clarify the use and interactions of -L and -l options.

Consider the case in which module a.c calls function f() in library libQ.a, and module b.c calls function g() in library libp.a. Assume that both libraries reside in /a/b/c. The command line to compile and link in the desired way is:

c99 -L /a/b/c main.o a.c -l Q b.c -l p

In this case the -L option need only precede the first -l option, since both libQ.a and libp.a reside in the same directory.

Multiple -L options can be used when library name collisions occur. Building on the previous example, suppose that the user wants to use a new libp.a, in /a/a/a, but still wants f() from /a/b/c/libQ.a:

c99 -L /a/a/a -L /a/b/c main.o a.c -l Q b.c -l p

In this example, the linker searches the -L options in the order specified, and finds /a/a/a/libp.a before /a/b/c/libp.a when resolving references for b.c. The order of the -l options is still important, however.

4. The following example shows how an application can use a programming environment where the widths of the following types: blksize_t, cc_t, mode_t, nfds_t, pid_t, ptrdiff_t, size_t, speed_t, ssize_t, suseconds_t, tcflag_t, wchar_t, wint_t

are no greater than the width of type long:

# First choose one of the listed environments ...

# ... if there are no additional constraints, the first one will do: CENV=$(getconf POSIX_V7_WIDTH_RESTRICTED_ENVS | head -n l)

# ... or, if an environment that supports large files is preferred, # look for names that contain "OFF64" or "OFFBIG". (This chooses # the last one in the list if none match.) for CENV in $(getconf POSIX_V7_WIDTH_RESTRICTED_ENVS) do case $CENV in *OFF64*|*OFFBIG*) break ;; esac done

# The chosen environment name can now be used like this:

c99 $(getconf ${CENV}_CFLAGS) -D _POSIX_C_SOURCE=200809L \ $(getconf ${CENV}_LDFLAGS) foo.c -o foo \ $(getconf ${CENV}_LIBS)