GCC compilation process, C language compilation process analysis, environment variable settings, Linux folder structure and purpose introduction, Common Files and directories operation command, file type

Source: Internet
Author: User

Reference Link: http://www.cnblogs.com/ggjucheng/archive/2011/12/14/2287738.html

http://blog.csdn.net/novrose/article/details/7670477

Http://blog.sina.com.cn/s/blog_7d5d42b40100ulqn.html

First, the difference between the case suffix

. s assembly language source program;
. S assembly language source program; preprocessing, compilation

lowercase s files, which are not preprocessed at the later stage, so we can't write preprocessing statements in here.

Uppercase S files, but also preprocessing, assembly, and so on, so we can add pre-processing commands in this area

An out file is a file with an out extension that does not itself represent any information. In Linux to determine whether a file is an executable file, the first thing to see whether the file's properties are executable, it does not have a default extension to indicate that this file is an executable file. For convenience, executables in Linux generally do not have a name extension.

--------------------------------------------------------------------------------------------------------------- ---------------------------

1. A.C-----> A.I-----> A.S------> A.O-------> A.out

Pretreatment: Gcc-e a.c-o A.I

Compile to assembly code: Gcc-s A.i-o A.S, generate assembly file. S

Compilation: Gcc-c a.s o A.o,gas Assembler is responsible for compiling it as a target file

Link: gcc a.o-o a GCC connector is provided by gas and is responsible for connecting the program's target file with all the additional target files needed to eventually generate the executable file. Additional target files include a static connection library and a dynamic connection library.

For the TEST.O generated in the previous section, connect it to the C standard input and output library, and the resulting program test

2./A

./indicates this level directory, if not added, the system will automatically go to the directory of the environment variable to find a

.. /indicates the previous level of the directory

~/

/

Environment Variables and PHP syntax

3. Environment variables

System-Level environment variables:

User-level environment variables:

View command: Export env set

Set reference links for environment variables: http://www.jb51.net/LINUXjishu/77524.html

Environment variables file and configuration in Linux : http://www.cnblogs.com/mengyan/archive/2012/09/04/2669894.html

4. library File connection

When developing software, it is relatively uncommon to not use a third-party library at all, usually with the support of many libraries to complete the function. From the programmer's point of view, the library is actually a collection of header files (. h) and library files (so, or LIB, DLLs). Although most of the functions under Linux are placed in the/usr/include/directory by default, and the library files are placed in the/usr/lib/directory, the library files used by Windows are mainly placed in the include and Lib under the directory of Visual Stido. and the System folder. But there are times when we need to use a library that is no longer in these directories, so GCC must use its own method to find the required header and library files at compile time.

For example, our program test.c is to use C to connect MySQL on Linux, this time we need to go to MySQL official website download MySQL connectors c library, download and unzip, there is an include folder, which contains MySQL Connectors's header file, and a Lib folder containing binary so files libmysqlclient.so

Where the path to the Inclulde folder is the/usr/dev/mysql/include,lib folder is/usr/dev/mysql/lib

5.1 compiling into an executable file

First we want to compile test.c as the target file, this time need to execute

Gcc–c–i/usr/dev/mysql/include Test.c–o TEST.O
5.2 Links

Finally, we link all the target files to the executable file:

Gcc–l/usr/dev/mysql/lib–lmysqlclient test.o–o Test

The library files under Linux are divided into two categories: dynamic-link libraries (usually ending with. So) and static-link libraries (usually ending with. A), except that the code required to execute the program is dynamically loaded at run time, or statically at compile time.

5.3 Using static link libraries when linking is mandatory

By default, GCC takes precedence over dynamic-link libraries when linking, and only considers static-link libraries when the dynamic-link library does not exist, and, if needed, with the-static option at compile time, forcing static-link libraries to be used.

In order for GCC to use only static link libraries when linking, you can use the following command when you need the library files libmysqlclient.so and libmysqlclient.a in the/usr/dev/mysql/lib directory:

Gcc–l/usr/dev/mysql/lib–static–lmysqlclient test.o–o Test

Search path order when static library links:

1. LD will go to the parameters in the GCC command-l
2. Re-search for GCC environment variables Library_path
3. Find the default directory/lib/usr/lib/usr/local/lib This is the original compile GCC when written in the program

Dynamic Link-time, execution-time search path order:

1. The dynamic library search path specified when compiling the target code
2. Environment variable LD_LIBRARY_PATH the specified dynamic library search path
3. The dynamic library search path specified in configuration file/etc/ld.so.conf
4. Default dynamic library search path/lib
5. Default dynamic Library search path/usr/lib

About environment variables:
Library_path environment variable: Specifies the program static link library file search path
LD_LIBRARY_PATH environment variable: Specifies the program dynamic link library file search path

5. Description of the structure and usage of the folders under Linux

Http://www.cnblogs.com/yyyyy5101/articles/1901842.html

Http://www.cnblogs.com/wen858636827/archive/2012/12/26/2834373.html

6. Common file and Directory operations commands

Http://www.cnblogs.com/ggjucheng/archive/2012/08/22/2650464.html

7. Large summary of Linux file types

Http://www.jb51.net/LINUXjishu/151838.html

GCC compilation process, C language compilation process analysis, environment variable settings, Linux folder structure and purpose introduction, Common Files and directories operation command, file type

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.