"Makefile 만들기"의 두 판 사이의 차이

59번째 줄: 59번째 줄:


===컴파일 하기===
===컴파일 하기===
*object 파일 생성
;object 파일 생성
<source lang='console'>
<source lang='console'>
$ gcc -c -o a.o a.c
$ gcc -c -o a.o a.c
65번째 줄: 65번째 줄:
$ gcc -c -o main.o main.c
$ gcc -c -o main.o main.c
</source>
</source>
:→ -c 는 컴파일, 어셈블 수행
:→ -o 는 파일명을 정함


*실행 파일 생성
;실행 파일 생성
<source lang='C'>
<source lang='C'>
gcc -o exefile main.o a.o b.o
gcc -o exefile main.o a.o b.o
</source>
</source>
:→ 링킹하여 실행파일 생성


* 실행파일 실행해보기
;실행파일 실행해보기
<source lang='C'>
<source lang='C'>
$ ./exefile
$ ./exefile

2018년 6월 13일 (수) 20:13 판

1 개요

makefile 만들기
How to make the makefile
  • make 빌드를 위한 makefile 만들기

2 make 란?

3 makefile 이란?

4 컴파일 예제

4.1 파일 개요

  • a.c (a.h), b.c (b.h), main.c 파일을 각각 만들어 보자

Files.png

4.2 파일 코드 내용

a.c
#include <stdio.h>

void foo()
{
    printf("foo\n");
}
a.h
void foo();
b.c
#include <stdio.h>

void bar()
{
    printf("bar\n");
}
b.h
void bar();
main.c
#include "a.h"
#include "b.h"

int main()
{
    foo();
    bar();

    return 0;
}

4.3 컴파일 하기

object 파일 생성
$ gcc -c -o a.o a.c
$ gcc -c -o b.o b.c
$ gcc -c -o main.o main.c
→ -c 는 컴파일, 어셈블 수행
→ -o 는 파일명을 정함
실행 파일 생성
gcc -o exefile main.o a.o b.o
→ 링킹하여 실행파일 생성
실행파일 실행해보기
$ ./exefile
foo
bar

작성중...

5 같이 보기

문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}