FreeBSD to manually compile the installer

Source: Internet
Author: User
Tags versions

Although compiling and installing software using ports collection is easy, there are still two reasons to use the manual compilation installation method. On the one hand, ports collection can not cover all the software, there are many software has no revenue ports collection. There are a number of reasons why some very good software has not been collected into ports Collection, for example, copyright factors, or no volunteers have migrated it to FreeBSD for maintenance. On the other hand, even if you are customizing the software through port, you still need to understand the process of compiling the installation manually and the use of various compiler tools to perform custom work properly.

It is usually not difficult to compile and install the application under FreeBSD because FreeBSD is a very standard UNIX, and the standard C program developed for UNIX can easily be compiled and run on it.

Compilation and software tools

In order to compile and install an application, you must understand the general method of compiling and running the software. For large programs and highly efficient software, it is often developed using advanced language C to compile the C source program into an executing program using the C language compiler. Because the use of high-level languages does not depend on the hardware structure, this makes the software very easy to migrate. Unix not only provides compilers, but also provides a number of tools to help with compilation and maintenance, and the most useful tool is make.

GNU c and Compile connection process

C as a compiled high-level language, that is, to run the C program before the first compiled into an executable machine instructions composed of the execution of the program, so you need to use a compiler to the C source code processing, FreeBSD using the GNU C compiler.

$ cc hello.c
$ ./a.out
Hello, world!

UNIX defaults to using a.out as the generated file name, you can use the-o parameter to indicate the generated execution file name.

In fact, the previous compilation of the build execution file consists of two steps, one is to generate the target file, usually using the. o suffix, and then the connection generation execution file. Therefore, you can use AR to combine multiple target files into a single function library file, and you can use NM to view the contents of a library file.

$ cc -c f1.c
$ cc -c f2.c
$ ar c mlib.a f1.o f2.o
$ nm mlib.a

FreeBSD uses the C language compiler GCC is a very popular, multi-platform, efficient C language compiler, which provides a variety of options for building applications. The following are some of the most common options:

-L

To define a directory for a connection library file

-I.

Directory to define header files for C source code

-O

The following argument is the name of the execution file to be generated

-O

For compilation optimizations, you can specify different optimization levels, from O2 to O6, with different optimization settings for each level.

Related options also have parameters that define the type of script generated, such as-m486 generates 486 directives, and the default GCC version (2.7.2) does not support Pentium code.

-G

Adding debug code, you can use the Strip command to remove information for debugging after completion

-C

Build the target file simply by compiling without making a connection

-fpic

Generate a relative address code that is used to finally generate a dynamic connection library

-static

To force a program to generate a static connection

-aout

Generate a.out format executable file, target code, etc., using the ELF format by default

-elf

3.0 after the default setting, the target and execution code for the ELF format is generated

You can view the version of the GNU C compiler currently in use using command-line arguments:

$ cc –version
Gcc version 2.7.2.1

FreeBSD currently uses the GNU C compiler gcc version for GCC 2.7.2.1, which is not the latest version of the GCC compiler, but is very stable. Although the current new version of GCC 2.8 is already stable, because of the compiler's importance in the system, compiler problems can cause system stability problems, so FreeBSD has not yet turned to GCC 2.8. Another important reason for not fully using GCC 2.8 is the resulting file format problem, and GCC 2.8 no longer supports generating binaries for a.out execution formats. But a complete shift to GCC version 2.8 is an inevitable trend, and GCC 2.8 has been used as a standard configuration in the FreeBSD 4.0-current currently under development.

In a 3.1 system, if you want to use GCC 2.8, you need to install the gcc-2.8 package provided in packages Collection (or compile the source code with ports Collection). In fact, there are two more powerful compilers that are further developed according to GCC, PGCC support Pentium code (standard GCC only supports generating 486 code), EGCC provides greater optimization capabilities in addition to supporting Pentium code. These versions are developed by commercial companies based on GCC, but under the GPL, any user can choose to use them as needed and use these compiler versions to further develop the system's capabilities.

Contact Us

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

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.