2018-04-26 "Bird Brother's Linux private cuisine Basic Study (Fourth Edition)" 21st Chapter Software Installation _ original code and Tarball notes

Source: Internet
Author: User
Tags diff sin

First, what is open source, compile program and executable file
On a Linux system, a file can be executed to see if there is no executable (with X-permission), but the actual executable file that the Linux system really reads is actually a binary file (binary program). For example,/USR/BIN/PASSWD,/bin/touch These files are binary program code.
1.1. Noun definition:
? Open Source: Is the program code, written to the human look of the program language, but the machine does not know, so unable to execute. such as the C-language source file with *.c as the extension.
? Compiler: Translating program code into machine-seen language, similar to the role of translators. For example, a target file with *.O as the extension (object files).
? Executable: After the compiler becomes the binary program, the machine can read the files that are able to execute. This type of file does not have a suffix, and the terminal input "path/filename" is executed.
? Library: A functional function that can be called to perform a function similar to the role of a subroutine.
The. conf suffix of the file three config is the abbreviation for the configuration file suffix.

Second, the process of compiling the program:
Because the system calls used by different versions of the Linux distribution core may not be the same, and the dependent function libraries required for each software are not the same. Software developers want to do development for the entire unix-like, not only for Linux development, so it must be detected that the operating system platform does not provide the appropriate compiler program. Software developers usually write a detection program called configure (or config), which detects data that is generally as follows:
? Is there a compilation program that can be translated into software program code?
? Whether there is a library of functions required for the software, or other dependent software required.
? Whether the operating system platform is suitable for the software, such as whether the core version of Linux meets the requirements.
? The core header definition file (header include) is present (the driver must be detected).
The makefile (or makefile) file is established to detect compliance, and the Makefiel file content is the details of how the source code is compiled.
The Make command compiles, which simplifies the command of the compilation process. Make executes, in the current directory search makefile file, according to this makefile file to determine whether the original code has been changed, if there is a change in the implementation of the update file.
2.1, the same set of software to be executed on different platforms, must be recompiled. Because the following information may not be the same for different Linux distribution:
1. The path placed by the function library file
2. Set the file name of the function library
3, pre-installed compiler program
4, the core version


Command:
File path/file name #查看文件是否为binary:
1, is binary and can be executed, the execution results will show the execution file category (ELF 64-bit lsbexecutable), and also indicate whether to use dynamic function library (shared libs).
2, is the general script, the execution result will display the text executables and the like words.


gcc [Options] Directory/file name #将源码编译为编译程序.
In the C language source file, just add "include <math.h>", the GCC command will take the function to you.
Options:
Null: Skip the Generate compile file step and generate the file directly under the current directory with the executable file named A.out. Overwrite the previous a.out file if a.out already exists.
C: Source program, preprocessing, compilation, compilation
-O: The target file (object files) is passed to the connector (linker)
-O: Optimization
-wall: Displays more detailed information about the compilation process. The displayed warning message (warning) can be ignored.
-LM: Joins the libm.so function library. L: Add a function library, the lab's shorthand. Shorthand for the M:libm.so function library, where Lib is omitted from the extension (. so or. a).
-l/path: Search the directory for the corresponding function library of the L-parameter. , because the Linux preset is to place the function library in the/lib and the/lib64, so-l/lib and-l/lib64 write and not write does not affect.
I/path: Defines the directory where the include file is to be read in the header of the C language source file
-i/path: In the path below, look for the include file defined in the header of the C language source file. The include file is placed by default in the/usr/include directory, except if the include file is placed on a different path, otherwise skip this option.

Instance:
[Email protected] ~]# gcc hello.c #将hello. CC language source files are compiled and built into an executable file named A.out by default.

[[email protected] ~]# gcc-c hello.c #将hello. CC language source file compilation, generating a target file named hello.o
[Email protected] ~]# gcc-o Hello hello.o #将hello. o Compile file compile, generate executable file named Hello

[[email protected] ~]# gcc-c thanks.c thanks_2.c #将thanks. C, thanks_2.cc language source files compiled, generated files named THANKS.O, THANKS_2.O 2 target files
[Email protected] ~]# gcc-o thanks thanks.o thanks_2.o #将thanks. o thanks_2.o target file compile, generate 1 executables with file name thanks

[Email protected] ~]# Gcc-o-C thanks.c thanks_2.c
[Email protected] ~]# gcc-wall-c thanks.c thanks_2.c

[Email protected] ~]# gcc sin.c-lm-l/lib-l/lib64 #要的函式库 libm.so please search in/lib or/lib64

[Email protected] ~]# gcc sin.c-lm-i/usr/include #C语言源码文件当中第一行 "#include <stdio.h>", which says to read some of the definition data by stdio.h this file This includes the relevant settings for printf. This file is placed in/usr/include/stdio.h, so in case this file is not placed here, use this method


Make command
Instance
# 1. Edit makefile This rule file first
[Email protected] ~]# VI makefile
LIBS =-lm
OBJS = main.o HAHA.O sin_value.o cos_value.o
CFLAGS =-wall
Main: ${objs}
Gcc-o [email protected] ${OBJS} ${libs} <[email protected] is the main
Clean
Rm-f Main ${OBJS}

# 2. Take the goal clean, main test to see the results of make
[[email protected] ~]# make clean
[email protected] ~]# make main
[[email protected] ~]# make clean main
[[email protected] ~]# cflags= "-wall" makes clean main #执行makefile文件内的gcc命令时, adding the contents of the CFLAGS variable as parameters.

Makefile file Format:
Target: Target file 1 target file 2
<tab> Gcc-o to set up the execution file target file 1 target file 2
? # represents annotations in makefile.
? <tab> requires the first character on the command line (such as the GCC compiler command).
? The target is separated from the dependent file (that is, the target file) with a ":".

The variable syntax for the makefile file is somewhat different from the syntax of Bash shell script:
1. Variables and variable contents are separated by "=" and can have spaces on both sides.
2. There is no <tab> on the left side of the variable, such as the first line of the example above LIBS the left side cannot be <tab>.
3. Variables and variable contents cannot have ":" on both sides of "=".
4. In practice, variables are best dominated by "capital letters".
5. When using variables, use the ${variable} or $ (variable).
6. Variables can also be given in command-line mode.
7. The environment variables in the shell can be applied, such as Cflags =-wall in the instance.
8. "[Email protected]" on behalf of the current goal (target)

Priority level of environment variable access:
1. The environment variable that is added to the Make command column is preferred;
2. Makefile the environment variables specified in the second;
3. The shell originally has the environment variable third.

Benefits of the Make command:
? Simplify the commands you need to release at compile time.
? Once a source file is modified after compilation, make will only compile for the modified file, and the other object file will not be altered.
? Updates (update) execution files according to dependencies.



Third, Tarball software
A Tarball package is formed by packaging all the original code files of the software before compressing it with compression.
? The Tarball file with the Tar packaging feature and the GZIP compression feature has the extension *.tar.gz or *.tgz.
? The Tarball file with bzip2 and XZ is compressed with the extension *.tar.bz2, *.tar.xz.
? Recently due to bzip2 and XZ compression ratio is better, so tarball gradually with bzip2 and XZ compression technology to replace Gzip.
The files in the Tarball package are usually:
? source code files;
? Detection program file (may be configure or config file name);
? Simple instructions and installation instructions for the software (install or README).

A tarball Software Installation process (GCC mode):
1. Download the Tarball from the manufacturer's webpage;
2. untie the Tarball and generate a lot of original code files;
3. Start the compilation of the original code with GCC (object files will be generated);
4. Then, the link of the function library, main and subroutine is carried out in GCC to form the main binary file;
5. Install the binary file above and the associated configuration file on its own host.
3rd, 4 steps can be simplified by the make command

Tarball Basic steps for Software installation (make mode):
1. Obtain the original file: The Tarball file is extracted in the/USR/LOCAL/SRC directory;
2. Get the step flow: Under the newly established directory, go to the INSTALL and README and other related documents (very important steps!);
3. Dependency Properties Software Installation: According to the content of Install/readme and install some dependent software (not necessary);
4. Establish makefile: detect the working environment with the Automatic detection program (configure or config) and establish the makefile file;
5. Compile: Make this program and use the Makefile in this directory as his parameter configuration file for making (compile or other) action;
6. Install: To make this program, and to Makefile this parameter configuration file, based on the installation of the target specified to install to the correct path.

Tarball Order of the Software Installation:
1../configure
Create a Makefile file. Usually the program developer will write a scripts to check your Linux system, related software properties and so on, this step is quite important, because in the future, your installation information is completed in this step! In addition, the relevant information of this step should refer to the directory of the README or install Related files.
2. Make clean
The make command reads the work about clean in Makefile. This step does not have to be, but hopefully, because he can get rid of the target file! Because no one is sure whether the original code contains the last compiled target file (*.O) exists, so of course, it is more appropriate to clear. At least wait a minute. The newly compiled execution file can be determined to be compiled using our own machine.
3. Make
The make command compiles according to the preset work in the Makefile. The main task of compiling is to do GCC to compile the original code into an object file that can be executed, but these object files usually require a link such as a function library to produce a complete execution file. Use make is to compile the original code into executable files that can be executed, and this executable file will be placed in the current directory, not installed in the directory of the scheduled installation;
4. Make install
Usually this is the final installation step, and make will be installed according to the Makefile in this file about the install of the project, the previous step compiled by the data to install him to the scheduled directory, the installation is complete.
The above steps are taken step-by-step, and as long as one step is unsuccessful, then the subsequent steps are completely out of the way!

Path to the default installation software for Linux distribution:
? /ETC/HTTPD configuration file
? /usr/lib function Library
? /usr/bin Executing files
? /usr/share/man online Help file

Recommendations when users install Tarball software themselves:
1. Extract the original data from the Tarball to/USR/LOCAL/SRC (the abbreviation for SRC as source).
2. When installing, install to/usr/local this default path.
3. Each software will provide the service of the online Help (info and man function), by default, the Man command will go to search the/usr/local/man directory of the description file, so if we install the software under/usr/local, then after the natural installation is completed, the The documentation for the software can be found. But consider the easy way to trace the source of the file when uninstalling, or install each software separately in/usr/local/software (corresponding software name)/directory.
4. Add the man path search parameter for the software's man page. In the/etc/man_db.conf within the 40~50 line, write: "Manpath_map/usr/local/software/bin/usr/local/software/man", so that you can use man To inquire about the software's online files!
5. Today, it is really not necessary to have a Tarball installation! Centos/fedora has a RPM addendum plan (or EPEL program), related website: Https://fedoraproject.org/wiki/EPEL. There are good friends to help us pack the usual software, in addition to proprietary software (money) software or relatively unpopular software, the general academic will use the software inside. ^_^

Tarball software Upgrade Update method:
? Install and upgrade directly from the original code through compilation. Directly with Tarball on their own machine to detect, compile, install and set up and other actions. This action allows the user to have a high level of flexibility in the installation process, but it is troublesome.
? Install and upgrade directly with the compiled binary program. Linux distribution manufacturers for their own job platform to compile the process, and then the compiled binary program released, the user's system environment and the Linux distribution environment, the vendor released binary Program can be installed directly on the user's machine! The complex process of detection and compilation is omitted.

Update the original code. Use the diff and patch command:
[Email protected] main-0.1]# vim ~/main_0.1_to_0.2.patch
Diff-naur main-0.1/cos_value.c main-0.2/cos_value.c
---main-0.1/cos_value.c 2015-09-04 14:46:59.200444001 +0800
+ + + main-0.2/cos_value.c 2015-09-04 14:47:10.215444000 +0800
@@ -7,5 +7,5 @@
{
float value;
.... (omitted below) ....
[Email protected] main-0.1]# PATCH-P1 <. /main_0.1_to_0.2.patch




Description of the function library:
The core of Linux provides a lot of core related function libraries and external parameters, these core functions are very useful information when designing the hardware driver, these core related information are mostly placed in/usr/include,/usr/lib,/usr/lib64 inside.



LDD [-VDR] [filename] #判断某个可执行的 binary file contains what dynamic function library
Options and Parameters:
-V: Lists all content information.
-D: Re-show the link point where the data is missing.
-R: Show the wrong ELF-related content.

2018-04-26 "bird Brother's Linux private dishes Basic Study (fourth Edition)" 21st Chapter Software Installation _ original code and Tarball notes

Related Article

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.