본문 바로가기

프로그램언어/C/C++

GCC Compile 옵션 및 과정

GCC Simple Option

 

-Idir 옵션

dir은 디렉토리 이름 이고 -I와 디렉토리 이름을 붙이면 라이브러리를 찾아준다.

 

-Dmacro

Ex) -DMAXLEN=255 = #define MAXLEN 255

 

-M Makefile파일을 만들 때 파일 컴파일 규칙을 stdout에 찍어준다.

 

-Wall 모든 경고 메시지를 출력하도록 한다.

 

-O -O2 -O3 최적화 모드 뒤로 갈수록 더 빠르게 많은 옵션으로 최적화를 한다.

 

-p, -pg 프로파일링

gcc -pg -o main main.cpp

gprof hello gmon.out

 

ar -t /usr/lib/libc.a

ar -r libsample.a main.o

 

GCC Compile 과정

 

  1. preprocessing

    • gcc -E main.cpp
  2. compling

    • cc1
    • cc1plus
  3. Assembling

    • gcc -S main.cpp
    • gcc -c main.cpp 링크를 하지말고 object 코드까지만 만들어라 하는 옵션
  4. Linking

    • -static dynamic linking을 지원하고 있는 시스템에서 static linking을 하라는 옵션

'프로그램언어 > C/C++' 카테고리의 다른 글

[AIX]dynamic library & static library  (0) 2012.03.24
POSIX 와 Thread-safety  (0) 2012.03.24
GCC 사용법  (0) 2012.03.24
xlC 컴파일 옵션 - AIX  (0) 2012.03.24
Compiler의 종류에 따른 옵션  (0) 2012.03.24