C language compiler cc typical usage

C language compiler cc typical usage

Install the C language compiler

sudo apt-get install build-essential

Use:
cc -std=c99 -Wall hello.h -o hello
The specific meaning is as follows:

  • cc: The command of the C language compiler, which is used to convert the C code into an executable file.
  • -std=c99: Specifies to compile using the C99 standard.
  • -Wall: Enables all warning messages so the compiler can spot potential problems or errors in the code.
  • hello.h: The C source code file that needs to be compiled, here it is assumed to be a file named "hello.h".
  • -o hello: Specify the name of the compiled executable file as "hello", where "hello" is an arbitrary name, you can use any name you like.

C99 (or the third edition of the C language standard) is an updated version of the C language, with the following differences from earlier versions (such as C89 or ANSI C):

  1. Variable-length arrays (Variable-length arrays): Allows the length of the array to be allocated dynamically at runtime rather than determined at compile time. This opens up more possibilities for writing more flexible code.

  2. Compound literals: Allows the creation of a temporary, anonymous compound type object that can be used in a program. This avoids creating an explicitly named object, making the code cleaner.

  3. _BoolBoolean type (Boolean type): A built-in Boolean type named is introduced , which allows to directly use the trueand falsekeywords to represent Boolean values, thus making the code more readable.

  4. Single-line comments (Single-line comments): Allows the use of //symbols to represent single-line comments, making code comments more convenient.

  5. Other language features: The C99 standard introduces some other new language features, such as enhanced support for compound statements, function declarations can be placed anywhere, official support for long long types, and more.

In addition to C99, there are many C language standards, including:

  1. C90 (also known as ANSI C): The first standard version of the C language, published by the American National Standards Institute (ANSI) in 1989. The C90 standard defines the basic syntax and semantics of the C language and becomes the basis for subsequent versions.

  2. C11: Also known as the fourth edition of the C language standard, it was released by the International Organization for Standardization (ISO) in 2011. The C11 standard has made some revisions and extensions to C99, adding some new language features, such as support for multi-threaded programming, support for generic programming, and so on.

  3. C18: Also known as the fifth edition of the C language standard, it was released by the International Organization for Standardization (ISO) in 2018. The C18 standard has made some minor revisions and improvements to C11, adding some new features and improvements, but overall it is basically the same as C11.

Typical usage of cc command

  1. Compile a single C language source file:

    cc source.c -o output

    This command will compile the source file source.c and name the output file output.

  2. Compile multiple C language source files:

    cc source1.c source2.c -o output

    This command will compile the source files source1.c and source2.c and name the output file output.

  3. Specify compiler standards:

    cc -std=c99 source.c -o output

    This command will compile the C99-compliant source file source.c and name the output file output.

  4. Show verbose output from the compiler:

    cc -v source.c -o output

    This command will display the detailed output of the compiler, including the options used by the compiler, library files and other information.

  5. Specify the search path for header files:

    cc -I/path/to/include source.c -o output

    This command will search the header file in the specified path (/path/to/include) to compile the source file source.c correctly, and name the output file as output.

  6. Specify the search path for library files:

    cc -L/path/to/lib source.c -o output -lmylib

    This command will search the library file in the specified path (/path/to/lib) to link the source file source.c correctly, and name the output file output. At the same time, a library file named mylib is also used.

Guess you like

Origin blog.csdn.net/SmileBasic/article/details/130453530