|
|
|
|
|
|
|
Á¦¸ñ: ¸®´ª½º C Compile ¹× Make »ç¿ë¹ý |
ÀúÀÛ±ÇÀº ÀúÀÚ¿¡°Ô ÀÖ½À´Ï´Ù |
|
ÀúÀÚ: Á¤ÀçÁØ(rgbi3307@nate.com) |
ÃÖ±Ù¼öÁ¤ÀÏ:2008-12-13 |
|
|
|
|
¸®´ª½º C Compile ¹× Make »ç¿ë¹ý 1. C ÄÄÆÄÀÏ ¹æ¹ý 2. ¶óÀ̺귯¸® »ý¼º ¹× »ç¿ë¹ý 3. Make »ç¿ë¹ý |
1. C ÄÄÆÄÀÏ ¹æ¹ý
¸ÕÀú, ¾Æ·¡¿Í °°ÀÌ °£´ÜÇÑ C Äڵ带 ÀÛ¼ºÇÑ´Ù.
ÆÄÀϸí: hello.c
|
#include <stdio.h> int main () { printf (¡°Hello World\n¡±); exit(0); } |
À§ÀÇ ÆÄÀÏÀ» ÄÄÆÄÀÏ, ¸µÅ©ÇÏ¿© ½ÇÇàÇÑ´Ù.
|
$ cc –c hello.c ©¬ ÄÄÆÄÀÏ $ ll -rw-rw-r-- 1 jungjj jungjj 79 12¿ù 13 08:41
hello.c -rw-rw-r-- 1 jungjj jungjj 840 12¿ù 13 08:49
hello.o ©¬ object ÄÚµå »ý¼ºµÊ $ cc -o hello hello.o ©¬ ¸µÅ© $ ll -rwxrwxr-x 1 jungjj jungjj 11638 12¿ù 13 08:51 hello ©¬ ½ÇÇàÆÄÀÏ »ý¼ºµÊ -rw-rw-r-- 1 jungjj jungjj 79 12¿ù 13 08:41
hello.c -rw-rw-r-- 1 jungjj jungjj 840 12¿ù 13 08:49
hello.o $ ./hello ©¬ ½ÇÇà Hello World |
¾Æ·¡¿Í °°ÀÌ ÄÄÆÄÀϰú
¸µÅ©¸¦ ÇѲ¨¹ø¿¡ ÇÏ¿© ½ÇÇàÆÄÀÏÀ» »ý»ýÇÒ ¼öµµ ÀÖ´Ù.
|
$ cc –o hello hello.c ©¬ ÄÄÆÄÀÏ ¹× ¸µÅ©ÇÏ¿© ½ÇÇàÆÄÀÏ »ý¼º |
2. ¶óÀ̺귯¸® »ý¼º ¹× »ç¿ë¹ý
À̹ø¿¡´Â C ÄÚµåÆÄÀÏÀ» ¿©·¯ °³ ¸¸µé¾î¼ object Äڵ带 »ý¼ºÇÏ°í ¸µÅ·ÇÏ´Â ¹æ¹ýÀÌ´Ù. ¶ÇÇÑ ¼ºêÄڵ带 ¶óÀ̺귯¸®·Î »ý¼ºÇÏ¿© ¸µÅ·ÇÏ´Â ¹æ¹ý¿¡ ´ëÇØ¼µµ ¾Ë¾Æº¸ÀÚ.
¸ÕÀú, ¾Æ·¡¿Í °°ÀÌ 2°³ÀÇ ¼ºêÄÚµåÀ» »ý¼ºÇÑ´Ù.
ÆÄÀϸí: bill.c
|
#include <stdio.h> void bill (char* arg) { printf (¡°bill: %s\n¡±, arg); } |
ÆÄÀϸí: fred.c
|
#include <stdio.h> void fred (char* arg) { printf (¡°fred: %s\n¡±, arg); } |
À§ÀÇ ¼ºêÄڵ带
ÄÄÆÄÀÏÇÏ¿© object Äڵ带 »ý¼ºÇÑ´Ù.
|
$ cc –c fred.c bill.c $ ll *.o -rw-rw-r-- 1 jungjj jungjj 788 12¿ù 13 09:21
bill.o -rw-rw-r-- 1 jungjj jungjj 788 12¿ù 13 09:21
fred.o |
À§ÀÇ ¼ºêÄڵ带
¸ÞÀÎÄڵ忡¼ »ç¿ëÇϱâ À§ÇÏ¿©, Çì´õÆÄÀÏ¿¡ ¼±¾ðÇÑ´Ù.
ÆÄÀϸí: lib.h
|
void fred (char*); void bill (char*); |
¸ÞÀÎÄڵ忡¼ À§ÀÇ
Çì´õÆÄÀÏÀ» Æ÷ÇÔ½Ã۰í, ¼ºêÄÚµå ÇÔ¼ö¸¦ È£ÃâÇÑ´Ù.
ÆÄÀϸí: program.c
|
#include ¡°lib.h¡± int main () { bill (¡°hello¡±); fred (¡°hello¡±); exit(0); } |
¸ÞÀÎÄڵ带 ÄÄÆÄÀÏÇϰí, ¼ºêÄÚµå object¿Í ¸µÅ©ÇÏ¿© ½ÇÇàÆÄÀÏÀ» ¸¸µç´Ù.
|
$ cc -c program.c $ cc -o program program.o bill.o
fred.o $ ll -rw-rw-r-- 1 jungjj jungjj 78 12¿ù 13 09:20
bill.c -rw-rw-r-- 1 jungjj jungjj 788 12¿ù 13 09:21
bill.o -rw-rw-r-- 1 jungjj jungjj 82 12¿ù 13 09:15
fred.c -rw-rw-r-- 1 jungjj jungjj 788 12¿ù 13 09:21
fred.o -rw-rw-r-- 1 jungjj jungjj 41 12¿ù 13 09:27
lib.h -rwxrwxr-x 1 jungjj jungjj 11912 12¿ù 13 09:28 program ©¬ ½ÇÇàÆÄÀÏ »ý¼ºµÊ -rw-rw-r-- 1 jungjj jungjj 78 12¿ù 13 09:27
program.c -rw-rw-r-- 1 jungjj jungjj 884 12¿ù 13 09:28
program.o $ ./program ©¬ ½ÇÇà bill: hello fred: hello |
À̹ø¿¡´Â ar ÇÁ·Î±×·¥À» »ç¿ëÇÏ¿© ¼ºêÄڵ带 ¶óÀ̺귯¸® ÆÄÀÏ·Î »ý¼ºÇØ º¸ÀÚ. À̶§ ar ÇÁ·Î±×·¥Àº object ÆÄÀϵéÀ» ÇÕÇÏ¿© archive ÆÄÀÏÀ» »ý¼ºÇÏ´Â ¿ªÇÒÀ» ÇÑ´Ù.
|
$ ar crv lib_billfred.a bill.o fred.o a - bill.o a - fred.o $ ll -rw-rw-r-- 1 jungjj jungjj 78 12¿ù 13 09:20
bill.c -rw-rw-r-- 1 jungjj jungjj 788 12¿ù 13 09:21
bill.o -rw-rw-r-- 1 jungjj jungjj 82 12¿ù 13 09:15
fred.c -rw-rw-r-- 1 jungjj jungjj 788 12¿ù 13 09:21
fred.o -rw-rw-r-- 1 jungjj jungjj 41 12¿ù 13 09:27
lib.h -rw-rw-r-- 1 jungjj jungjj 1786 12¿ù 13 09:34
lib_billfred.a ©¬ ¶óÀ̺귯¸® ÆÄÀÏ »ý¼º -rwxrwxr-x 1 jungjj jungjj 11912 12¿ù 13 09:28 program -rw-rw-r-- 1 jungjj jungjj 78 12¿ù 13 09:27
program.c -rw-rw-r-- 1 jungjj jungjj 884 12¿ù 13 09:28
program.o |
À§¿¡¼ »ý¼ºÇÑ
¶óÀ̺귯¸® ÆÄÀÏÀ» ¸µÅ©ÇÏ¿© ½ÇÇàÆÄÀÏÀ» »ý¼ºÇÏ¿© ½ÇÇàÇÑ´Ù.
|
$ cc –o program program.o
lib_billfred.a $ ./program bill: hello fred: hello |
À§ÀÇ ¸µÅ©¸í·ÉÀ»
¾Æ·¡¿Í °°ÀÌ »ç¿ëÇØµµ µÈ´Ù. ¿©±â¼
–L.´Â ¶óÀ̺귯¸® ÆÄÀÏÀÇ À§Ä¡°¡ ÇöÀç Æú´õ¿¡ ÀÖ´Ù´Â ÀǹÌÀ̰í, -l_billfred´Â ¶óÀ̺귯¸® ÆÄÀϸíÀ» ÀǹÌÇÑ´Ù.
|
$ cc -o program program.o -L.
-l_billfred $ ./program bill: hello fred: hello |
¸®´ª½º¿¡¼´Â »ç¿ëÇÏ´Â
ÆÄÀϰú DOS ÆÄÀÏ ¸íĪÀ» ºñ±³ÇÏ¸é ¾Æ·¡¿Í °°´Ù.
|
ÆÄÀϱ¸ºÐ |
Linux/Unix |
DOS |
|
Object ¸ðµâ |
func.o |
FUNC.OBJ |
|
°øÀ¯ ¶óÀ̺귯¸® |
lib.so |
LIB.DLL |
|
Á¤Àû ¶óÀ̺귯¸® |
lib.a lib.sa |
LIB.LIB |
|
½ÇÇà ÇÁ·Î±×·¥ |
program |
PROGRAM.EXE |
3. Make »ç¿ë¹ý
À̹ø¿¡´Â À§¿¡¼
½Ç½ÀÇÑ ÄÚµåµéÀ» make ÆÄÀÏÀ» »ç¿ëÇÏ¿© ºôµåÇØ º¸ÀÚ. ¸ÕÀú ¾Æ·¡¿Í °°ÀÌ make ÆÄÀÏÀ» »ý¼ºÇÑ´Ù.
ÆÄÀϸí: make_file1
|
myapp: program.o bill.o fred.o gcc
-o myapp program.o bill.o fred.o program.o: program.c lib.h gcc
-c program.c bill.o: bill.c gcc
-c bill.c fred.o: fred.c gcc
-c fred.c |
make ÇÁ·Î±×·¥À» »ç¿ëÇÏ¿© À§ÀÇ ÆÄÀÏÀ» ½ÇÇàÇÑ´Ù.
|
$ make -f make_file1 gcc -o myapp program.o bill.o fred.o $ ll -rw-rw-r-- 1 jungjj jungjj 78 12¿ù 13 09:20
bill.c -rw-rw-r-- 1 jungjj jungjj 788 12¿ù 13 09:21
bill.o -rw-rw-r-- 1 jungjj jungjj 82 12¿ù 13 09:15
fred.c -rw-rw-r-- 1
jungjj jungjj
788 12¿ù 13 09:21 fred.o -rw-rw-r-- 1 jungjj jungjj 41 12¿ù 13 09:27
lib.h -rw-rw-r-- 1 jungjj jungjj 1786 12¿ù 13 09:34
lib_billfred.a -rw-rw-r-- 1 jungjj jungjj 179 12¿ù 13 10:08
make_file1 -rwxrwxr-x 1 jungjj jungjj 11912 12¿ù 13 10:09 myapp ©¬ ½ÇÇàÆÄÀÏ »ý¼ºµÊ -rwxrwxr-x 1 jungjj jungjj 11912 12¿ù 13 09:41 program -rw-rw-r-- 1 jungjj jungjj 78 12¿ù 13 09:27
program.c -rw-rw-r-- 1 jungjj jungjj 884 12¿ù 13 09:28 program.o $ ./myapp ©¬ ½ÇÇà bill: hello fred: hello |
Áö±Ý±îÁö ¸®´ª½º
ȯ°æ¿¡¼ C ÄÚµåÆÄÀÏÀ» ÄÄÆÄÀÏÇÏ°í ¸µÅ©ÇÏ¿© ½ÇÇàÆÄÀÏÀ» »ý¼ºÇÏ´Â ¹æ¹ýÀ» °£´ÜÈ÷ ±â¼ú ÇÏ¿´´Ù. ¾Æ¿ï·¯ make ÆÄÀÏÀ» ÅëÇÏ¿© ºôµåÇÏ´Â ¹æ¹ý¿¡ ´ëÇØ¼µµ ¾ð±Þ ÇÏ¿´´Ù.
|
|
|
|
|
|
|
|
|
|
Á¦¸ñ: ¸®´ª½º C Compile ¹× Make »ç¿ë¹ý |
ÀúÀÛ±ÇÀº ÀúÀÚ¿¡°Ô ÀÖ½À´Ï´Ù |
|
ÀúÀÚ: Á¤ÀçÁØ(rgbi3307@nate.com) |
ÃÖ±Ù¼öÁ¤ÀÏ:2008-12-13 |