Linux GCC makeÎļþµÄд·¨ ×ܽá°æ
Ŀ¼½á¹¹Îª£º
inc/hello.h
src/hello.c
main/main.c
Makefile
ÎļþÄÚÈÝΪ£º
hello.h:
void hello(char name[]);
hello.c:
#include <stdio.h>
void hello(char name[])
{
printf("Hello %s!\n", name);
}
main.c:
#include <stdio.h>
#include "hello.h"
// The second hello.h should in ""
int main()
{
hello("GCC");
printf("Haha Linux Ubuntu!\n");
return 0;
}
Makefile:
# String declaration
objects = main.o hello.o
# Command
app : $(objects)
cc -o app $(objects)
main.o : main.c hello.h stdio.h
cc -c $< -I ./inc
hello.o : hello.c stdio.h
cc -c $<
# Search paths
vpath %.h /usr/include : inc
vpath %.c main : src
# Clean the intermediate files
.PHONY : clean
clean :
rm app *~ $(objects)
Ê×ÏÈ£¬ÐèÒªÃ÷È·Ò»µã£¬ÕâÀïÃæÓÐÁ½¸öÖ´ÐгÌÐò£¬Ò»¸ömake£¬Ò»¸ögcc£¬ÔÚMakefileÀïÕâÁ½¸öµÄÓï¾äÒ²ÊÇ·Ö±ðÕ¼1Ðеġ£
ÕâÀï×îÖ÷ÒªµÄÊÇ·¾¶µÄÎÊÌ⣬ÒòΪ²»Í¬µÄÎļþÔÚ²»Í¬µÄĿ¼ÏÂÃ棬ËùÒÔÒª¸æËß³ÌÐòÎļþËùÔڵķ¾¶£¬¶øÓÖÓÐÁ½¸ö³ÌÐòÐèÒª¸æÖª£¬¶øÁ½¸ö³ÌÐò¸æÖªµÄ·½Ê½ÓÖ²»Í¬£¬ËùÒÔÕâ¸öÎÊÌâÒ»¿ªÊ¼À§ÈÅÁËÎҺþã¬ÔںöàºÃÐÄÈ˵İïÖúÏ£¬ÖÕÓÚÃ÷°×ÁËÒ»µã¡£
makeµÄËÑË÷·¾¶ÉèÖ÷½Ê½Îª£ºvpath»òVPATH£¬Õâ¸öÔÚÐí¶à×ÊÁÏÀﶼ½²¹ý£¬¶øÇÒÕâ¸öÊÇËùÓÐÎļþ¶¼¿ÉÒÔÉèÖõģ¬.c, .h»¹ÓÐÆäËüµÄ¶¼¿ÉÒÔ¡£
gccµÄËÑË÷·¾¶ÉèÖ÷½Ê½Îª£¨Õâ¸öÓ¦¸ÃÊÇÖ»ÄÜÉèÖÃÍ·ÎļþµÄËÑË÷·¾¶£¬ÒòΪÊÇinclude£©£º-I inc£¬
¶ø.cÎļþµÄËÑË÷·¾¶Ëƺõ²»ÄÜÉèÖ㬶øÖ»ÄÜÔÚcc -c path/%.cÖÐÏÔʾµÄд³ö£¬¸öÈËÕâôÀí½â¡£
¶øÓÐÒ»ÖÖ·½Ê½ÊÇ¿ÉÒÔ²»ÓÃÏÔʾµÄд³öµÄ£¬¶øÇÒÒ²²»Óðɣ¬%.cҲд³ö£¬¾ÍÊÇÓÃmakeµÄ×Ô¶¯»¯±äÁ¿¡£
“$<”ºÍ“$@”ÔòÊÇ×Ô¶¯»¯±äÁ¿£¬“$<”±íʾËùÓеÄÒÀÀµÄ¿±ê¼¯£¨%.c£©£¬“$@”±íʾĿ±ê¼¯£¨%.o£©¡£
(ÊÇmakeµÄ±äÁ¿£¬ÎļþÔÚµ±Ç°Ä¿Â¼Ã»ÓÐÕÒµ½µÄ»°£¬»á×Ô¶¯ËÑË÷vpathÖÐÉèÖõÄ·¾¶£¬Èç¹û²»ÓÃÕâ¸öÄÇôÈç¹û.cÔÚ²»ÔÚµ±Ç°Ä¿Â¼Ï£¬-cºóÃæÒªÖ¸Ã÷Ŀ¼λÖã¬ÓÃÕâ¸öºó£¬¿ÉÒÔÔÚvpathÖÐÖ¸Ã÷¼´¿É£©
ÒòΪÊÇmakeµÄ±äÁ¿£¬ËùÒÔÓÃvpathÉèÖõÄmakeµÄ·¾¶ÔÚÕâÀïÃæ¾ÍÆð×÷ÓÃÁË£¬²»ÓÃÔÙÏÔʾµÄÖ¸Ã÷.cµÄ·¾¶ÁË¡£¶øÇÒÕâÑùдÆðÀ´£¬¸ü¼ò½à¡£
×î½üÔÚ¿´¡¶ÉîÈëÀí½â¼ÆËã»úϵͳ¡·ÍøÉÏÏÂÔصĴúÂ붼ÊÇÔÚLinuxÉÏÅܵģ¬ºÇºÇ£¬ËùÒÔµÃ×Ô¼ºÐ´Makefile£¬ËùÒÔ£¬Ñо¿ÁËһϣ¬ÖÕÓÚÕûÃ÷°
Ïà¹ØÎĵµ£º
ËùÐèÎļþhello.c, main.c, hello.h, Makefile£¬ÔÚͬһ¸öĿ¼ÏÂ
hello.c:
#include <stdio.h>
void hello(char name[])
{
printf("Hello %s!\n", name);
}
main.c:
#include "stdio.h"
#include "hello.h"
// The second
int main()
{
hello("GCC");
printf("Haha Linux Ubuntu!\n");
......
ÎļþÔÚÁ½¸öÎļþ¼Ð£º
inc/hello.h
main/hello.c, main.c, Makefile
ÎļþÄÚÈÝ£º
hello.h
void hello(char name[]);
hello.c
#include <stdio.h>
void hello(char name[])
{
printf("Hello %s!\n", name);
}
main.c
#include <stdio.h>
#include "../inc/hello.h"
// The second
int main( ......
Ò».²é¿´ËùÓÐÓ²Å̵Äuuid
ls -all /dev/disk/by-uuid
longseakerµÄʵÀý
lrwxrwxrwx 1 root root 10 2009-09-19 08:17 05434a61-8a78-4ee5- a5db-6a49079b9e3d -> ../../sda5
lrwxrwxrwx 1 root root 10 2009-09-19 08:17 07D8-0104 -> ../../sda1
lrwxrwxrwx 1 root root 10 2009-09-19 08:17 18201249-998a-4bb1 ......
ǶÈëʽϵͳÓëͨÓÃPC»ú²»Í¬£¬Ò»°ãûÓÐÓ²ÅÌÕâÑùµÄ´æ´¢É豸¶øÊÇʹÓÃFlashÉÁ´æоƬ¡¢Ð¡ÐÍÉÁ´æ¿¨µÈרΪǶÈëʽϵͳÉè¼ÆµÄ´æ´¢×°Ö㬱¾ÎÄ·ÖÎöÁËǶÈëʽϵͳÖг£ÓõĴ洢É豸¼°Æä¹ÜÀí»úÖÆ£¬½éÉÜÁ˳£ÓõĻùÓÚFLASHµÄÎļþϵͳÀàÐÍ¡£
1£®Ç¶Èëʽϵͳ´æ´¢É豸¼°Æä¹ÜÀí»úÖÆ·ÖÎö
¡¡¡¡¹¹½¨ÊÊÓÃÓÚǶÈëʽϵͳµÄLi ......