티스토리 뷰

- vim 설치

# yum install vim


# vi ~/.bashrc


추가

alias vi='vim'


변경사항 적용

# source ~/.bashrc


vi



- vim 설정


# vi ~/.vimrc (사용자 적용)

또는

# vi  /etc/vimrc (전체 적용)


설정 추가

set nocp                    " Use Vim defaults (much better!)
set bs=2                    " allow backspacing over everything in insert mode
set ai                      " always set autoindenting on
set nobackup                " no keep a backup file
set viminfo=                " read/write a .viminfo file, don't store more 
set hi=100                  " keep 100 lines of command line history
set ru                      " show the cursor position all the time

set paste
set nowrapscan
set vb                      " visualbell
set sc                      " showcmd
set sm                      " showmatch
set nu                      " toggle key: set number!
set et                      " expandtab
set ts=4                    " tabstop
set sw=4                    " shiftwidth
set ci                      " cindent
set si                      " smartindent
set ic                      " ignorecase
 
map<F3> :set number!<CR>
map<F4> :q!<CR>
map<F5> :wq<CR>
cs



:set

설정되어 있는 내역을 볼 수 있다.



- gcc 설치

# yum install gcc



- gdb 설치

# yum install gdb



Compilation process in GCC

The whole Compilation process is broken down into following 


phases:

1. Pre-processing (cpp : to expand macros)

Basically C Preprocessor is responsible for 3 tasks namely:

∙ Text Substitution

∙ Stripping of Comments

∙ File Inclusion

2. Compilation (cc : from source code to assembly language)

3. Assembly (as : from assembly language to machine code)

4. Linking (ld : to create the final executable)



1. The Preprocessor (The C preprocessor, often known as cpp)

hello.c ▸ hello.i


Text Substitution and File Inclusion is requested in our source code using Preprocessor Directives.

The lines in our code that begin with the “#” character are preprocessor directives.

In 'hello.c' program the first preprocessor directive requests a standard header file, stdio.h, be included into our source file. 

The other one requests a string substitution to take place in our code. So in preprocessor stage those included header files and defined macros are expanded and merged within the source file to produce a transitory source file, which the standard calls a Translation unit. Translation units are also known as compilation units.

The C preprocessor, often known as cpp, is a macro processor that is used automatically by the C compiler to transform a C program before compilation.To perform just preprocessing operation use the following command:

# cpp hello.c > hello.i

The result is a file named hello.i which contains the source code with all macros expanded.


By convention, preprocessed files are given the file extension ‘.i’ for C programs and ‘.ii’ for C++ programs.

NOTE: By default the preprocessed file is not saved to disk unless the -save- temps option is used in gcc so we are just using the redirection operator to save a copy of preprocessed file.

By using gcc's “-E” flag we can directly do the pre-processing operation.

# gcc -E hello.c -o hello.i



2. The Compiler (The C compiler, often known as cc)

hello.i ▸ hello.s


The next stage of the process is the actual compilation of the preprocessed source code to assembly language, for a specific processor (Depending upon the target processor architecture the source code is converted into particular assembly language and it can be known as cross-compilation).

By using “-S” flag with gcc we can convert the preprocessed C source code into assembly language without creating an object file:

# gcc -S hello.i -o hello.s

The resulting assembly language is stored in the file ‘hello.s’.



3. The Assembler (The Assembler, often known as as)

hello.s ▸ hello.o


We know that MACHINES (i.e. a computer) can understand only Machine-Level Code. So we require an ASSEMBLER that converts assembly code in "hello.s" file into machine code. Eventhough it is a straightforward one-to-one mapping of assembly language statements to their machine language counterparts, it is tedious and error-prone if done manually.

NOTE: ASSEMBLER was one of the first software tools developed after the invention of the digital electronic computer.

If there are any calls to external functions in the assembly code, the Assembler leaves the addresses of the external functions undefined, to be filled in later by the Linker.

The Assembler as in gcc can be invoked as shown below.

# as hello.s -o hello.o

As with gcc, the output file is specified with the -o option. The resulting file ‘hello.o’ contains the machine level code for 'hello.c' program.



By using “-c” flag in gcc we can convert the assembly code into machine level code:

# gcc -c hello.c

NOTE: Back in the days of the PDP computer, a.out stood for "assembler output". Today, it simply means an older executable file format. Modern versions of Unix and Linux use the ELF executable file format. The ELF format is much more sophisticated. So even though the default filename of the output of gcc is "a.out", its actually in ELF format.



4. The Linker (The Linker, often known as ld)

hello.o ▸ a.out


The final stage of the compilation process is producing a single executable program file by linking set of object files. An object file and an executable file come in several formats such as ELF (Executable and Linking Format) and COFF (Common Object-File Format). For example, ELF is used on Linux systems, while COFF is used on Windows systems.

In practice, an executable file requires many external functions from system and C run-time libraries. The linker will resolve all of these dependencies and plug in the actual address of the functions.

The linker also does a few additional tasks for us. It combines our program with some standard routines that are needed to make our program run. For example, there is standard code required at the beginning of our program that sets up the running environment, such as passing in command-line parameters and environment variables. Also, there is code that needs to be run at the end of our program so that it can pass back a return code, among other tasks. It turns out that this is no small amount of code.

the entire linking process is handled transparently by gcc when invoked as follows:

# gcc hello.o -o hello


This links the object file ‘hello.o’ to the C standard library, and produces an executable file ‘a.out’.

'Operating System > CentOS' 카테고리의 다른 글

HTTPD, MYSQL, PHP 설치 및 설정  (0) 2015.07.09
USER 관리  (0) 2015.07.08
TELNET 설치 및 설정  (0) 2015.07.08
FTP, VSFTPD 설치 및 설정  (0) 2015.07.03
iptables 방화벽 설정  (0) 2015.06.30
OpenSSH 설정  (0) 2015.06.30
Hostname & Login interface Message  (0) 2015.06.30
Network 설정  (0) 2015.06.11
Console 해상도 설정  (0) 2015.05.05
시스템 확인하기  (0) 2015.04.01
댓글
«   2024/12   »
1 2 3 4 5 6 7
8 9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30 31
링크
공지사항
Total
Today
Yesterday