GCC的简单使用 - webdancer's Blog

GCC的简单使用

webdancer posted @ 2010年9月08日 12:08 in 工具 with tags os GCC , 1535 阅读

 

这学期要学操作系统的课程设计了,编译器的学习是必需的了。当然,由于平台基于Linux,所以学习GCC是必须的了。

GCC 是“GNU Compiler Collection” 的简称,而不是以前的 “GNU C Compiler “。它支持 c ,c++,object-c,objectc+,Fortran,Java和Ada。 GCC编译器的选项真的非常之多,通常可以分成三种:

1.平台相关的选项。所谓的平台,是指机器(主要是芯片)和OS。下表:

 

Hardware

Operating System

 

PowerPC

Linux

 

Sparc

Linux

 

ARM

Linux

 

Intel x86

Cygwin Linux

 

2.语言相关的选项。

3.一般性选项。

GCC的编译过程:

预处理、编译、汇编、链接;通过一定的gcc选项,可以使编译过程停留在某一阶段。例如:-C 可以阻止链接过程,只是产生目标文件。文件的后缀通常决定怎么编译。例如:

.a

Static object library (archive).

.c

C source code that is to be preprocessed.

.h

C source code header file.

.i

C source code that is not to be preprocessed. This type of file is

produced as an intermediate step in compilation.

.o

An object file in a format appropriate to be supplied to the linker.

This type of file is produced as an intermediate step in compilation.

.s

Assembly language code. This type of file is produced as an

intermediate step in compilation.

 

集中常用的gcc命令:

(1)、单个源文件产生可执行文件。

命令:源文件:a.c

gcc a.c

结果:产生a.out 可执行文件。

(2)、产生目标文件。

命令:gcc -c a.c -o a.o

结果:产生a.o目标文件。

(3)、多个源文件产生可执行文件。

命令: gcc a.c b.c -o a

(4)、预处理。

命令: gcc -E a.c -o a.i

(5)、产生汇编文件。

命理: gcc -S a.c

(6)、创建静态库。

命令:gcc -c a.c b.c

ar -r liba.a a.o b.o

(7)、创建动态库。

命令:gcc -c -fpic a.c b.c

gcc -shared a.o b.o -o a.so

(8)、避免后缀转换。

命令: gcc -xc a.ccc (-x 后面跟具体的语言。)

 


 

NCERT Question Paper 说:
2022年9月24日 20:31

NCERT Sample Paper 2023 Pdf Download for 1st, 2nd, 3rd, 4th, 5th, 7th, 8th, 9th, 10th, 11th & 12th Standard Sample Pape Suggestions for Hindi Medium, English Medium & Urdu Medium students studying at CBSE, KVS, NCERT Question Paper Pdf Download JNV and other Central & State Education Boards of the Countr.NCERT Sample Paper 2023 Pdf Download for 1st, 2nd, 3rd, 4th, 5th, 7th, 8th, 9th, 10th, 11th & 12th Standard Sample Pape Suggestions for Hindi Medium, English Medium & Urdu Medium students studying at CBSE, KVS, JNV and other Central & State Education Boards of the Country.NCERT Sample Paper 2023 Pdf Download for 1st, 2nd, 3rd, 4th, 5th, 7th, 8th, 9th, 10th, 11th & 12th Standard Sample Pape Suggestions.


登录 *


loading captcha image...
(输入验证码)
or Ctrl+Enter
Host by is-Programmer.com | Power by Chito 1.3.3 beta | © 2007 LinuxGem | Design by Matthew "Agent Spork" McGee