LinuxUNIX Programming Compile Makefile IT C 29 Compile

  • Slides: 37
Download presentation
Linux/UNIX Programming Compile & Makefile 문양세 강원대학교 IT대학 컴퓨터과학전공

Linux/UNIX Programming Compile & Makefile 문양세 강원대학교 IT대학 컴퓨터과학전공

C 프로그램 컴파일 (2/9) Compile & Makefile 기본적인 사용법 $ cc hello. c •

C 프로그램 컴파일 (2/9) Compile & Makefile 기본적인 사용법 $ cc hello. c • hello. c를 컴파일하여 object file인 hello. o를 만듦 • 또한, 실행 가능한 파일(executable file)로서 a. out을 만듦 Page 3 Linux/UNIX Programming by Yang-Sae Moon

C 프로그램 컴파일 (3/9) Compile & Makefile 주요 옵션(-c) $ cc –c hello. c

C 프로그램 컴파일 (3/9) Compile & Makefile 주요 옵션(-c) $ cc –c hello. c • Object code(기계어 코드)만 생성하며, 실행 파일은 만들지 않음 • 상기 예의 경우, hello. c를 컴파일하여 object code인 hello. o를 만듦 Page 4 Linux/UNIX Programming by Yang-Sae Moon

C 프로그램 컴파일 (8/9) Compile & Makefile 주요 옵션(-S) $ cc –S hello. c

C 프로그램 컴파일 (8/9) Compile & Makefile 주요 옵션(-S) $ cc –S hello. c • 어셈블리 언어(assembly language)로 컴파일 함 • 상기 예의 경우 hello. s의 어셈블리 파일이 생성됨 Page 12 Linux/UNIX Programming by Yang-Sae Moon

C 프로그램 컴파일 (8/9) Compile & Makefile 주요 옵션(-S) $ cc –S hello. c

C 프로그램 컴파일 (8/9) Compile & Makefile 주요 옵션(-S) $ cc –S hello. c • 어셈블리 언어(assembly language)로 컴파일 함 • 상기 예의 경우 hello. s의 어셈블리 파일이 생성됨 Page 13 Linux/UNIX Programming by Yang-Sae Moon

단일 모듈 프로그램 (2/2) Page 17 Compile & Makefile Linux/UNIX Programming by Yang-Sae Moon

단일 모듈 프로그램 (2/2) Page 17 Compile & Makefile Linux/UNIX Programming by Yang-Sae Moon

다중 모듈 프로그램 (3/8) Compile & Makefile operation_main. c의 소스 코드 Page 20 Linux/UNIX

다중 모듈 프로그램 (3/8) Compile & Makefile operation_main. c의 소스 코드 Page 20 Linux/UNIX Programming by Yang-Sae Moon

다중 모듈 프로그램 (5/8) Compile & Makefile operation_plus. c와 operation_minus. c 소스 코드 Page

다중 모듈 프로그램 (5/8) Compile & Makefile operation_plus. c와 operation_minus. c 소스 코드 Page 22 Linux/UNIX Programming by Yang-Sae Moon

다중 모듈 프로그램 (6/8) Compile & Makefile operation_plus. h와 operation_minus. h 소스 코드 헤더

다중 모듈 프로그램 (6/8) Compile & Makefile operation_plus. h와 operation_minus. h 소스 코드 헤더 파일에 포함되는 일반적인 내용 • 함수의 prototype (상기 파일이 예제에 해당함) • 상수에 대한 정의 (#define MY_PI 3. 141592) • 전역 변수에 대한 정의 (extern int common_pi) Page 23 Linux/UNIX Programming by Yang-Sae Moon

Makefile (5/10) Compile & Makefile 구성 (계속) • 파일 operation_main. o는 세 개의 파일

Makefile (5/10) Compile & Makefile 구성 (계속) • 파일 operation_main. o는 세 개의 파일 “operation_main. c”, “operation_plus. h”, “operation_minus. h”에 관계됨 • 즉, 이 세 개의 파일 중 하나라도 변경되면 “operation_main. c”를 컴파일하여 “operation_main. o”가 재구성되어야 함 • 다음은 main. mk내의 나머지 규칙을 나타낸다. operation_main. o: operatoin_main. c operation_plus. h operation_minus. h gcc –c operation_main. c operation_plus. o: operatoin_plus. c operation_plus. h gcc –c operation_plus. c operation_minus. o: operatoin_minus. c operation_minus. h gcc –c operation_minus. c Page 31 Linux/UNIX Programming by Yang-Sae Moon

Makefile (7/10) Compile & Makefile Make 규칙의 순서 (계속) • make 유틸리티는 의존 리스트

Makefile (7/10) Compile & Makefile Make 규칙의 순서 (계속) • make 유틸리티는 의존 리스트 내의 각 파일과 연관된 각 규칙에 대해서도, 동일한 동작 을 반복한다. • 앞의 예에 대한 최종적인 트리는 다음과 같다. main operation_main. o “_main. c “_plus. h “_minus. h operation_plus. o “_plus. c “_plus. h operation_minus. o “_minus. c “_minus. h 최종 make 의존 트리 Page 33 Linux/UNIX Programming by Yang-Sae Moon

Makefile (9/10) Compile & Makefile 예제: main. mk Page 35 Linux/UNIX Programming by Yang-Sae

Makefile (9/10) Compile & Makefile 예제: main. mk Page 35 Linux/UNIX Programming by Yang-Sae Moon

Makefile (10/10) Compile & Makefile의 실행 ($ make [-f makefile]) Page 36 Linux/UNIX Programming

Makefile (10/10) Compile & Makefile의 실행 ($ make [-f makefile]) Page 36 Linux/UNIX Programming by Yang-Sae Moon

Homework#6 Page 37 Linux/UNIX Programming by Yang-Sae Moon

Homework#6 Page 37 Linux/UNIX Programming by Yang-Sae Moon