Apple’s M1 chip is Apple’s fastest single-core CPU benchmark on a Mac, and it beats many high-end Intel competitors in multi-core performance. Developer Erik Engheim recently shared an in-depth look at the M1 chip, exploring why Apple’s new processor is so much faster than the Intel chip it replaces. M1 is not a CPU! First, the M1 is not a simple CPU. As Apple explains, itR...
The c compiler is one of the indispensable components for parsing c programs. For linux systems, the gcc c compiler is undoubtedly one of the most popular c compilers. For the gcc c compiler, many friends have reported that its operation is difficult. In order to help you use the gcc c compiler more smoothly, this article explains the major parameters of the gcc c compiler.
gcc and g++ are gnu’s c & c++ compilers gcc/g++. When performing compilation work, a total of 4 steps are required:
1. Preprocessing to generate .i files[预处理器cpp]
2. Convert the preprocessed file into assembly language and generate the file .s [编译器egcs]
3. There are files that are assembled into object code (machine code) to generate .o[汇编器as]
4. Connect the object code to generate an executable program [链接器ld]
-x language filename
Set the language used in the file, make the extension name invalid, and make it valid for the following multiple. That is, according to the convention, the suffix name of C language is .c, and the suffix name of C++ is .C or .cpp. If you are very individual, you decide that the suffix name of your C code file is .pig. Haha, then you have to use This parameter, this parameter has an effect on the file name after it, unless the next parameter is used. Possible parameters are the following: ‘c’, ‘objective-c’, ‘c-header’, ‘c++’, ‘cpp-output’, ‘assembler’, and ‘assembler-with-cpp’.
It should be understandable in English.
gcc -xc hello.pig
-x none filename
Turn off the previous option, that is, let gcc automatically recognize the file type according to the file name suffix.
gcc -xc hello.pig -x none hello2.c
Only activate preprocessing, compilation, and assembly, that is, he only makes the program into an obj file
gcc -c hello.c
He will generate .o obj files
Activating only preprocessing and compilation means compiling the file into assembly code.
gcc -S hello.c
It will generate .s assembly code that you can view with a text editor.
Only activate preprocessing, this does not generate a file, you need to redirect it to an output file.
gcc -E hello.c > pianoapan.txt
gcc -E hello.c | more
Take it slow, a hello word also needs to be processed into 800 lines of code.
Specify the target name. By default, the file compiled by gcc is a.out, which is ugly. If you feel the same as me, change it, haha.
gcc -o hello.exe hello.c (oh, windows are used to it)
gcc -o hello.asm -S hello.c
Using pipes instead of temporary files during compilation may have some problems when using non-gnu assembly tools.
gcc -pipe -o hello.exe hello.c
Turn off the features that are incompatible with ansi c in gnu c, and activate the proprietary features of ansi c (including prohibiting some asm inline typeof keywords, and UNIX, vax and other preprocessing macros).
This option implements part of the functionality of the ansi option, which prohibits the use of asm, inline and typeof as keywords.
It only works for g++. With this option, g++ treats functions without parameters as having no explicit specification of the number and type of parameters, rather than having no parameters.
And whether gcc uses this parameter or not, it will treat functions without parameters as a type that is not explicitly stated.
It is to be in line with traditional C++, you can use this as a general variable.
The type mismatch between the second and third parameters of the conditional expression is allowed, and the value of the expression will be of type void.
-funsigned-char, -fno-signed-char, -fsigned-char, -fno-unsigned-char
These four parameters are to set the char type, and decide to set the char type to unsigned char (the first two parameters) or signed char (the last two parameters).
Including a certain code, in simple terms, is to use a certain file, when another file is needed, you can use it to set, the function is equivalent to using #include in the code.
gcc hello.c -include /root/pianopan.h
The macros in file file are expanded to the input file of gcc/g++, and the macro definition itself does not appear in the input file.
Equivalent to #define macro in C language
Equivalent to #define macro=defn in C language
Equivalent to #undef macro in C language
Undefine any non-standard macros
When you use #include “file”, gcc/g++ will first look for the header file you have specified in the current directory. If it is not found, it will go back to the default header file directory to find it. If the directory is specified with -I, He will first look in the directory you made, and then look for it in the usual order.
For #include, gcc/g++ will search in the directory specified by -I, if it can’t find it, then it will search in the system’s default header file directory.
It is to cancel the function of the previous parameter, so it is generally used after -Idir.
The search in the -I directory failed, and the search in this directory is mentioned.
-iprefix prefix, -iwithprefix dir
Generally used together, when the -I directory search fails, it will search under prefix+dir
Make the compiler no longer look for header files in the default header file directory of the system, generally used in conjunction with -I to clearly define the location of the header files.
Specifies not to search in the standard paths specified by g++, but still in other paths, this option is used when creating the libg++ library.
During preprocessing, comment information is not deleted, generally used with -E, and sometimes it is very convenient to use this for analysis programs.
Generate file association information. Contains all the source code that the object file depends on. You can use gcc -M hello.c to test it, very simple.
Same as the one above, but it will ignore dependencies caused by #include.
Same as -M, but the output will be imported into a .d file
Same as -MM, but the output will be imported into a .d file.
This option passes the option to the assembler; if there is a comma in the option, the option is divided into multiple options, and then passed to the assembler.
This option passes the option to the linker; if there is a comma in the option, the option is split into multiple options and then passed to the linker.
Specify the library to use when compiling
gcc -lcurses hello.c
Compile programs using the ncurses library
Specify the path to search for libraries when compiling. For example, your own library, you can use it to make a directory, otherwise the compiler will only find it in the directory of the standard library. The dir is the name of the directory.
-O0 , -O1 , -O2 , -O3
There are 4 levels of compiler optimization options, -O0 means no optimization, -O1 is the default value, and -O3 is the highest optimization level.
It’s just that the compiler, when compiling, produces debug information.
This option claims debug information in stabs format, but does not include gdb debug information.
This option claims debug information in stabs format, and includes additional debug information for use by gdb only.
This option will generate as much debug information as possible for gdb.
This option will prohibit the use of dynamic libraries, so the compiled things are generally very large and can run without any dynamic link library.
This option will try to use the dynamic library, so the generated file is relatively small, but it needs the system to use the dynamic library.
The above is the relevant content of the “c compiler” brought by the editor this time. I hope you can understand the common parameters of the gcc c compiler through this article. Finally, thank you very much for reading, hava a nice day!