Линукс gcc все команды
When you invoke GCC, it normally does preprocessing, compilation, assembly and linking. The “overall options” allow you to stop this process at an intermediate stage. For example, the -c option says not to run the linker. Then the output consists of object files output by the assembler. See Options Controlling the Kind of Output.
Other options are passed on to one or more stages of processing. Some options control the preprocessor and others the compiler itself. Yet other options control the assembler and linker; most of these are not documented here, since you rarely need to use any of them.
Most of the command-line options that you can use with GCC are useful for C programs; when an option is only useful with another language (usually C++), the explanation says so explicitly. If the description for a particular option does not mention a source language, you can use that option with all supported languages.
The usual way to run GCC is to run the executable called gcc , or machine -gcc when cross-compiling, or machine -gcc- version to run a specific version of GCC. When you compile C++ programs, you should invoke GCC as g++ instead. See Compiling C++ Programs, for information about the differences in behavior between gcc and g++ when compiling C++ programs.
The gcc program accepts options and file names as operands. Many options have multi-letter names; therefore multiple single-letter options may not be grouped: -dv is very different from ‘ -d -v ’ .
You can mix options and other arguments. For the most part, the order you use doesn’t matter. Order does matter when you use several options of the same kind; for example, if you specify -L more than once, the directories are searched in the order specified. Also, the placement of the -l option is significant.
Many options have long names starting with ‘ -f ’ or with ‘ -W ’—for example, -fmove-loop-invariants , -Wformat and so on. Most of these have both positive and negative forms; the negative form of -ffoo is -fno-foo . This manual documents only one of these two forms, whichever one is not the default.
Some options take one or more arguments typically separated either by a space or by the equals sign (‘ = ’) from the option name. Unless documented otherwise, an argument can be either numeric or a string. Numeric arguments must typically be small unsigned decimal or hexadecimal integers. Hexadecimal arguments must begin with the ‘ 0x ’ prefix. Arguments to options that specify a size threshold of some sort may be arbitrarily large decimal or hexadecimal integers followed by a byte size suffix designating a multiple of bytes such as kB and KiB for kilobyte and kibibyte, respectively, MB and MiB for megabyte and mebibyte, GB and GiB for gigabyte and gigibyte, and so on. Such arguments are designated by byte-size in the following text. Refer to the NIST, IEC, and other relevant national and international standards for the full listing and explanation of the binary and decimal byte size prefixes.
See Option Index, for an index to GCC’s options.
- Option Summary
- Options Controlling the Kind of Output
- Compiling C++ Programs
- Options Controlling C Dialect
- Options Controlling C++ Dialect
- Options Controlling Objective-C and Objective-C++ Dialects
- Options to Control Diagnostic Messages Formatting
- Options to Request or Suppress Warnings
- Options That Control Static Analysis
- Options for Debugging Your Program
- Options That Control Optimization
- Program Instrumentation Options
- Options Controlling the Preprocessor
- Passing Options to the Assembler
- Options for Linking
- Options for Directory Search
- Options for Code Generation Conventions
- GCC Developer Options
- Machine-Dependent Options
- Specifying Subprocesses and the Switches to Pass to Them
- Environment Variables Affecting GCC
- Using Precompiled Headers
- C++ Modules
Компилятор GCC C
GCC — это сокращение от GNU Compiler Collection, компилятора C для Linux.
Синтаксис GCC
$ gcc [options] [source files] [object files] [-o output file]
Параметры GCC
вариант | описание |
---|---|
gcc -c | компилировать исходные файлы в объектные файлы без связывания |
gcc -Dname[=value] | определить макрос препроцессора |
gcc -fPIC | генерировать независимый от позиции код для разделяемых библиотек |
gcc -glevel | генерировать отладочную информацию для использования GDB |
gcc -Idir | добавить каталог включения файлов заголовков |
gcc -llib | ссылка на файл библиотеки |
gcc -Ldir | поищите в каталоге файлы библиотеки |
gcc -o output file | записать вывод сборки в выходной файл |
gcc -Olevel | оптимизировать размер кода и время выполнения |
gcc -shared | создать файл общих объектов для общей библиотеки |
gcc -Uname | отменить определение макроса препроцессора |
gcc -w | отключить все предупреждающие сообщения |
gcc -Wall | включить все предупреждающие сообщения |
gcc -Wextra | включить дополнительные предупреждающие сообщения |
Примеры GCC
Скомпилируйте file1.c и file2.c и создайте ссылку на выходной файл execfile :
$ gcc file1.c file2.c -o execfile
Запустить выходной файл execfile :
Скомпилируйте file1.c и file2.c без связывания:
Скомпилируйте myfile.c с отладочной информацией и ссылкой на выходной файл execfile :
Скомпилируйте myfile.c с включенными предупреждающими сообщениями и сделайте ссылку на выходной файл execfile :
$ gcc -Wall myfile.c -o execfile
Скомпилируйте myfile.c и свяжите со статической библиотекой libmath.a, расположенной в / user / local / math, для вывода файла execfile :
$ gcc -static myfile.c -L/user/local/math -lmath -o execfile
Скомпилируйте myfile.c с оптимизацией и сделайте ссылку на выходной файл execfile :
GCC C Compiler
GCC is a short of GNU Compiler Collection, a C compiler for Linux.
GCC syntax
$ gcc [options] [source files] [object files] [-o output file]
GCC options
option | description |
---|---|
gcc -c | compile source files to object files without linking |
gcc -Dname[=value] | define a preprocessor macro |
gcc -fPIC | generate position independent code for shared libraries |
gcc -glevel | generate debug information to be used by GDB |
gcc -Idir | add include directory of header files |
gcc -llib | link with library file |
gcc -Ldir | look in directory for library files |
gcc -o output file | write build output to output file |
gcc -Olevel | optimize for code size and execution time |
gcc -shared | generate shared object file for shared library |
gcc -Uname | undefine a preprocessor macro |
gcc -w | disable all warning messages |
gcc -Wall | enable all warning messages |
gcc -Wextra | enable extra warning messages |
GCC examples
Compile file1.c and file2.c and link to output file execfile:
$ gcc file1.c file2.c -o execfile
Run output file execfile:
Compile file1.c and file2.c without linking:
Compile myfile.c with debug information and link to output file execfile:
Compile myfile.c with warning messages enabled and link to output file execfile:
$ gcc -Wall myfile.c -o execfile
Compile myfile.c with and link with static library libmath.a located in /user/local/math to output file execfile:
$ gcc -static myfile.c -L/user/local/math -lmath -o execfile
Compile myfile.c with optimization and link to output file execfile: