programming
6.1 C programming
source file을 Operating System이 인식 가능한 상태의 object file로 만드는 작업을 compile이라 하고 이러한 file들을 서로 연결시키는 과정을 link라 한다.
link 과정에서는 실제 실행 가능하게 하는 loader 과정 또한 포함되어 있다. loader 과정은 실행 코드를 재배치하는 과정을 말한다.
source file(*.c) --compile--> object file(*.o) --link--> executable file
6.1.1 c source compiling(gcc)
source file을 실행 가능한 파일로 만들기 위해 gcc를 이용한다.
6.1.2 예제 source
[root @edu00 linux]#vi main.c
#include<stdio.h>
void core()
{
printf("In main\n");
}
[root @edu00 linux]#vi hilinux.c
#include<stdio.h>
int main()
{
core();
printf("Hi Linux!!\n");
return 0;
}
[root @edu00 linux]#vi helloworld.c
#include<stdio.h>
int main()
{
core();
printf("Hellow world!!\n");
return 0;
}
6.1.3 object file
hilinux.o는 독립적으로 실행될 수 없다. main.o의 실행 코드가 필요하기 때문이다.
object file들은 서로 연결되어야 사용이 가능하게 된다.
[root @edu00 linux]#gcc -c main.c
: object file을 생성한다. source file과 같은 이름(main.o)으로 생성된다.
[root @edu00 linux]#gcc -c hilinux.c helloworld.c
: source를 한번에 object화 할 수 있다.
[root @edu00 linux]#ls *.o
[root @edu00 linux]#file hilinux.o
hilinux.o: ELF 32-bit LSB relocatable, Intel 80386, version 1, not stripped
: ELF 파일 형식의 재배치가 가능한 파일이다.
: ELF는 shared object를 사용하는 실행 파일 형태이며 리눅스의 기본 실행 파일
형태이다.
: not stripped는 디버깅을 위해서 정보를 파일 내에 남겨 두었다는 의미이다.
6.1.4 실행 파일
[root @edu00 linux]#gcc -o hilinux main.o hilinux.o
: 두 개의 object를 이용해서 hilinux라는 실행 파일을 만든다.
[root @edu00 linux]#gcc -o helloworld main.o helloworld.o
[root @edu00 linux]#gcc hilinux.c main.c
[root @edu00 linux]#gcc hilinux.o main.c
6.2 library 만들기
6.2.1 개요
프로그램을 만들 때 빈번하게 사용되는 부분들을 프로그램을 만들 때마다 매번 새롭게 작성해야 한다면 비효율적일 뿐만 아니라 기능을 확장하는 데도 어려움이 따른다. 이를 보완하기 이해 도입된 개념이 라이브러리와 동적 링크 기능이다.
대부분의 프로그램들이 공통적으로 사용하게 되는 기능들은 이미 별도의 object file로 만들어져서 /lib 디렉토리나 /usr/lib 디렉토리안에 들어 있으며, 프로그램을 작성할 때 이러한 라이브러리들을 자신의 프로그램에 포함시켜서 보다 간편하고 효율적인 프로그램을 만들 수 있다.
사용할 함수들의 루틴이 있는 object file들을 묶어서 library file을 만들 수 있다.
gcc를 이용할 때 필요한 object file들을 일일이 나열하는 것이 아니라 필요한 라이브러리 파일만 호출하면 된다.
6.2.2 예제
[root @edu00 linux]#vi helloworld.c
#include<stdio.h>
int main()
{
core();
sub();
printf("Hello world!!\n");
return 0;
}
[root @edu00 linux]#vi main.c
#include<stdio.h>
void core()
{
printf("In main\n");
}
[root @edu00 linux]#vi sub.c
void sub()
{
printf("sub function\n");
}
[root @edu00 linux]#gcc -c main.c sub.c
: object file을 만든다.
[root @edu00 linux]#ar r my_lib.a main.o sub.o
: 생성된 object file을 my_lib.a라는 파일로 묶어준다.
: r 옵션은 추가하고 d 옵션은 archive file에서 지운다.
[root @edu00 linux]#ranlib my_lib.a
: 라이브러리의 index를 생성한다.
[root @edu00 linux]#gcc -c helloworld.c
[root @edu00 linux]#gcc -o heloworld helloworld.o my_lib.a
: 라이브러리 파일과 object file을 이용해서 실행파일을 만든다.
6.3 Makefile
6.3.1 개요
compile 과정을 일괄적으로 처리해주는 tool이다. compile 과정을 Makefile이라는 file안에 기술하고 make 명령어가 파일을 참조하게 된다.
이때 Makefile은 make가 실행되는 디렉토리 안에 있어야 한다.
6.3.2 예제 소스
[root @edu00 linux]#vi main.c
#include<stdio.h>
void core()
{
printf("In main\n");
}
[root @edu00 linux]#vi hilinux.c
#include<stdio.h>
int main()
{
core();
printf("Hi Linux!!\n");
return 0;
}
[root @edu00 linux]#vi helloworld.c
#include<stdio.h>
int main()
{
core();
printf("Hellow world!!\n");
return 0;
}
6.3.3 Makefile 작성
[root @edu00 linux]#vi Makefile
all: hilinux helloworld
# 처음 target에 지정된 것만을 실행하게 된다. (#make라고 실행했을 때)
hilinux: hilinux.o main.o
# hilinux를 target line이라 한다.
gcc -o hilinux hilinux.o main.o
# 명령줄을 기술할 때는 반드시 <Tab>으로 시작해야 한다. commnad line이라 한다.
helloworld: helloworld.o main.o
gcc -o helloworld helloworld.o main.o
hilinux.o: hilinux.c
gcc -c hilinux.c
helloworld.o: helloworld.c
gcc -c helloworld.c
main.o: main.c
gcc -c main.c
-------------------------------------
[root @edu00 linux]#make
: 처음 target인 all에서 정의된 target들을 실행하게 된다.
: 이 명령을 내릴 때는 현재 디렉토리에 source file들과 Makefile이 있어야 한다.
: Makefile을 참조해서 일련의 작업들을 수행한다.
[root @edu00 linux]#make hilinux
: make의 인자로 Makefile에 있는 다른 target_name을 주면 그 target에 관련된
것들을 수행한다.
[root @edu00 linux]#vi Makefile(추가하기)
---------------------------------------
install:
[ -d /home/nadream/bin ] || mkdir /home/nadream/bin
: 디렉토리가 없다면 생성한다.
mv helloworld hilinux /home/nadream/bin
: nadream은 자신의 ID를 말한다.
clean:
rm -f `find . -name '*.[oa]' -print`
: 생성되었던 object file이나 library file을 제거한다.
------------------------------------------
[root @edu00 linux]#make install
: "install:" target만 실행한다.
[root @edu00 linux]#make clean
: "clean:" target만 실행한다.
게시글 목록
| 번호 | 제목 |
|---|---|
| 12201 | |
| 12200 |
기타
www 자동으로 붙이기
|
| 29244 | |
| 12196 | |
| 29243 | |
| 12188 | |
| 12184 |
Flash
Open Flash Chart
3
|
| 29231 |
HTML
타이틀 이미지 만드는 방법
11
|
| 29230 |
HTML
리코
|
| 12181 |
기타
툴팁
2
|
| 29229 | |
| 12179 | |
| 12177 | |
| 12173 |
Flash
서서히 늘어나는 리사이즈 팝업창
3
|
| 29226 | |
| 12172 |
정규표현식
자바스크립트 sort()를 이용한 숫자 정렬
|
| 25007 | |
| 12171 |
JavaScript
DOM 이용 select box 옵션추가삭제
|
| 12170 | |
| 29225 |
HTML
실수로 지운 데이터 살리기..
|
| 12167 | |
| 12166 |
JavaScript
아이디 중복체크
|
| 12157 |
기타
빈티지 효과만들기
8
|
| 12154 |
MySQL
그누보드 통합검색 방법...
2
|
| 12153 | |
| 25002 | |
| 12151 | |
| 29224 | |
| 12148 |
JavaScript
심플한 드롭다운 레이어 메뉴 (2단계 메뉴 구성)
2
|
| 29223 | |
| 12142 | |
| 29217 | |
| 12141 |
JavaScript
날짜 관련 쿼리 입니다. 한달을 요일별로 구함..
|
| 12136 | |
| 12132 | |
| 12130 |
MySQL
테이블 깨졌거나 복구 할때 간단한 팁.
1
|
| 29216 |
HTML
Table생성 스크립트 파일 뽑아내기
|
| 29215 | |
| 12126 | |
| 12124 |
JavaScript
마우스 오버시 그림 변하게 하는 스크립트 소스
1
|
| 12122 | |
| 12120 |
PHP
웹 서버를 이용한 인증
1
|
| 12111 |
JavaScript
div 사이즈 5픽셀로 하기. -_-
8
|
| 25001 | |
| 25000 | |
| 24999 | |
| 24998 | |
| 24997 | |
| 24994 | |
| 24985 | |
| 12109 | |
| 12105 | |
| 12104 | |
| 12096 | |
| 12094 | |
| 12091 | |
| 12090 |
MySQL
리눅스 mysql 에서 백그라운드 실행
|
| 12079 |
JavaScript
거리에서 찍은 인물사진 더 멋있게-
10
|
| 29211 |
HTML
낡은 포스터효과를 내어보자
3
|
| 12072 |
기타
돌아가는 글자
6
|
| 29210 |
HTML
구멍난 자바스크립트 보안
|
| 12070 | |
| 29207 |
HTML
올가미툴에 대해 배워보자
2
|
| 12067 |
JavaScript
div layer 위치 Javascript
2
|
| 12061 | |
| 29204 |
HTML
한글패치 삭제하는 방법
2
|
| 12058 | |
| 12057 | |
| 12056 |
PHP
php로 엑셀파일 만들기
|
| 24984 | |
| 12055 |
JavaScript
lampp 스타트 간단명령
|
| 12053 |
JavaScript
중앙정렬 사이트에 영향없이 오른쪽 배너 붙이기
1
|
| 12051 |
MySQL
apm
1
|
| 12050 |
MySQL
LOG
|
| 12049 | |
| 12048 |
기타
dhcp
|
| 12047 |
Linux
X 윈도우
|
| 12046 |
Linux
BOOT PROCESS
|
| 12045 |
Linux
Linux 명령어 사용방법
|
| 12044 | |
| 12043 |
JavaScript
vi
|
| 12042 |
기타
Nis/NFS
|
| 12041 |
PHP
User Management
|
| 12040 |
JavaScript
쉘
|
| 12039 |
기타
Process
|
| 12038 |
Linux
파일 시스템
|
| 12037 |
Linux
programming
현재글
|
| 12036 |
Flash
시스템 튜닝
|
| 12035 |
JavaScript
Quota
|
| 12034 |
MySQL
LOG
|
| 12033 | |
| 12032 |
Linux
메모리
|
| 12031 |
JavaScript
IPCHAINS
|
| 12028 | |
| 12026 |
Linux
linux + samba
1
|
| 12025 |
Linux
압축 그리고 백업( Backup)
|
| 12020 | |
| 12017 | |
| 12015 |
기타
이미지파일정보
1
|
| 12013 |
기타
아쿠아버튼
1
|
댓글 작성
댓글을 작성하시려면 로그인이 필요합니다.
로그인하기