In FreeBSD, GNUC compiler-compiler GCC-general Linux technology-Linux programming and kernel information. The following is a detailed description. The most basic development environment must support the C language. C is a compilation-type high-level language, this means that before running the C program, you must first compile it into an executable execution program consisting of machine commands. Therefore, you need to use a compiler to process the C source code, freeBSD uses the gnu c compiler. As the most popular compiler that supports the largest number of platforms, GCC provides excellent performance and efficiency.
According to the c language habits, the first program is usually hello. c:
$ Cat hello. c
Main ()
{
Printf ("Hello, world! N ");
}
The simple compilation process is as follows:
$ Cc hello. c
$./A. out
Hello, world!
In UNIX, a. out is used as the generated file name by default. You can use the-o parameter to indicate the generated execution file name.
In fact, the process of compiling and generating the execution file is composed of two steps. One is to generate the target file, which is usually suffixed with. o and then connected to generate the execution file.
Therefore, you can use ar to combine multiple target files into a function library file, and you can use nm to view the contents of the library file.
$ Cc-c f1.c
$ Cc-c f2.c
$ Ar c mlib. a f1.o f2.o
$ Nm mlib.
The C language compiler gcc used by FreeBSD is a popular multi-platform and efficient C language compiler. It provides multiple options for generating application software. The following are common options:
-L
Define the directory of the Connection Library File
-I
Directory that defines the header file of C source code
-O
The following parameter indicates the name of the execution file to be generated.
-O
For compilation optimization, you can specify different optimization levels, from O2 to O6. Different Levels use different optimization settings.
Related options also include parameters that define the generated script type. For example,-msag generates the 486 command. The default gcc version (2.7.2) does not support Pentium code.
-G
Add the debugging code. You can use the strip command to delete the debugging information.
-C
Only compile and not connect to generate the target file
-FPic
Generate the code of the relative address, which can be used to generate the dynamic Connection Library.
-Static
Generate a static Connection Program forcibly
-Aout
Generate the execution file and target code in a. out format. ELF format is used by default.
-Elf
After 3.0, the default setting is used to generate the target and Execution Code in ELF format.
You can use the command line parameters to view the version of the gnu c compiler currently in use:
$ Cc-version
Gcc version 2.7.2.1
FreeBSD currently uses the gnu c compiler, which is sometimes not the latest version of the gcc compiler, because sometimes the latest version of the software may inevitably cause minor issues. Of course, you can manually upgrade gcc to the latest version. This is an interesting connection.
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.
A Free Trial That Lets You Build Big!
Start building with 50+ products and up to 12 months usage for Elastic Compute Service