ºìÁªLinuxÃÅ»§
Linux°ïÖú

GNU/Linux¿ª·¢µÚÒ»²½

·¢²¼Ê±¼ä:2006-02-21 01:04:30À´Ô´:ºìÁª×÷Õß:cooc
Ä¿Ç°£¬ºÜ¶àÅóÓÑѧÍêÁËCÓïÑÔ£¬µ«²¢²»ÄÜÔÚGNU/LinuxϵͳϽøÐбà³Ì¿ª·¢¡£¾¿ÆäÔ­Òò£¬GNU/Linuxϵͳ»¹Î´´óÃæ»ýÆÕ¼°ÊÇ´ó°­Ö®Ò»£¬ÁíÍ⣬ÈËÃDz»ÊìϤGNU/LinuxϵͳϵĿª·¢¹¤¾ßÒ²Êǹؼü¡£±¾ÎľÍÊÇÒÔ¡°ÓÃÀý¡±µÄÐÎʽ½²ÊöÔÚGNU/LinuxϵͳÏÂÈçºÎ½øÐÐÓ¦ÓÃÈí¼þ¿ª·¢µÄ»ù´¡ºÍ³£Ê¶£¬Îª½«À´ÔÚGNU/LinuxϵͳÖнøÐдó¹æÄ£»òÆóÒµ¼¶¿ª·¢ÆÌ·¡£Ëùν¡°ÓÃÀý¡±£¬¾ÍÊÇͨ¹ý¼òµ¥µÄÀý×ÓÀ´Ñ§Ï°£¬×îÖÕ´ïµ½ÄÜÔÚ×Ô¼ºµÄʵ¼ÊÖÐÓ¦ÓõÄÄ¿µÄ¡£

±¾ÎÄÒªÇó¶ÁÕßÊìÁ·Linux²Ù×÷ϵͳµÄ³£ÓòÙ×÷£¬ÕÆÎÕCÓïÑÔÓï·¨£¬ÄÜÀí½âLinuxϵͳµÄ×é³ÉÔ­ÀíºÍÁ˽âShellºÍPerlµÈ½Å±¾ÓïÑÔ¡£

ƽ̨ѡÔñ

Ê×ÏÈ£¬´ÓÊÂGNU/Linux£¨ÒÔϼòÄãLinux£©ÏµÍ³ÏµÄÓ¦Óÿª·¢£¬Ó¦¸ÃÓÐÒ»¸öºÏÊʵIJÙ×÷ƽ̨ºÍ¿ª·¢»·¾³£¬ËùÒÔÑ¡ÔñºÍ°²×°Linux²Ù×÷ϵͳ³ÉΪLinux¿ª·¢ÕߵĵÚÒ»¿Î¡£Ä¿Ç°¿É¹©Ñ¡ÔñµÄLinux²Ù×÷ϵͳÖÖÀàºÜ¶à£¬ÈçRed Hat£¨×îаæÃûΪFedora£©¡¢SuSE¡¢MandrakeºÍÖпƺìÆ죨Red Flag£©£¬»¹ÓпªÔ´×éÖ¯ÖÐÓÐÃûµÄDebianµÈ¡£ËäÈ»°æ±¾ºÜ¶à£¬µ«ËüÃÇÔڵײãϵͳ×é³ÉÉϵIJî±ðÊÇ΢ºõÆä΢µÄ¡£ÎÒÃÇÒÔRed Hat 9.0Ϊ¿ª·¢Æ½Ì¨£¬ÒÔºóµÄ²Ù×÷ºÍ¿ª·¢¶¼ÔÚÕâһϵͳƽ̨ÉϽøÐС£

Linux²Ù×÷ϵͳÄں˵ײãµÄ¿ª·¢¹¤¾ßºÍ¸¨Öú¹¤¾ß£¬ÓеÄÊÇÖ±½Ó½¨Á¢ÔÚÄں˻ù´¡ÉÏ£¬ÈçShell¡¢GCCºÍMakeµÈ£»ÓеÄÊǽ¨Á¢Ôڽű¾ÓïÑԵĻù´¡Ö®Éϵģ¬ÈçAutomake¡¢AutoconfºÍLibtoolµÈ¡£ËüÃÇÊÇLinux²Ù×÷ϵͳÍâ²ãµÄͼÐνçÃ濪·¢¹¤¾ß£¨GTK+¡¢QTµÈ£©ºÍÍøÂçÓ¦Óÿª·¢¹¤¾ß£¨Perl¡¢PHPºÍPythonµÈ£©µÄ»ù´¡ºÍ¹ý¶É¡£ÕÆÎÕÁ˵ײ㿪·¢¹¤¾ß£¬¶ÔÍâ²ãÓ¦Óÿª·¢ÊÇÓкô¦µÄ£¬ÕâÑù¿ÉÒÔ¼Ó¿ìºÍÓÅ»¯Íâ²ãÓ¦Óÿª·¢£¬´Ó¶ø´ïµ½¿ª·¢ËٶȺͿª·¢ÖÊÁ¿µÄºÍгͳһ¡£

É÷Ñ¡IDE

±¾ÎĽ²ÊöµÄ³ÌÐò±à¼­¹¤×÷¶àÊýÊÇÓÃLinuxϵͳÖг£ÓõÄEmacsºÍviÀ´×ö£¬ÔÚÖն˴°¿ÚÖнøÐÐÃüÁî±àÒëµ÷ÊÔ¡£ÊìϤWindowsϱà³ÌµÄÅóÓÑÃÇ»áÖÊÒÉΪʲô²»ÓÃIDE£¨¼¯³É¿ª·¢»·¾³£©£¬ÊÇLinuxÏÂûÓÐÂ𣿴𰸵±È»ÊÇ·ñ¶¨µÄ¡£LinuxÏÂÓкܶàIDE£¬ÊÂʵÉÏEmacs¾ÍÊÇÒ»¸ö·Ç³£ºÃµÄIDE£¬ÆäËüµÄ»¹ÓÐCodeForge¡¢ANJUTAºÍKdeveloperµÈ¡£¶Ô±à³ÌÈËÔ±À´Ëµ£¬IDEÔÚ±àÒë¿ØÖƵĵײãÒþ²ØÁ˺ܶණÎ÷£¬Èç¹ûÈí¼þ¿ª·¢ÕßÕæÕýÁ˽âºÍÕÆÎÕÁËÕâЩ¶«Î÷£¬¶Ô¿ª·¢³ö¸üºÃµÄÓ¦ÓóÌÐòÊÇ´óÓаïÖúµÄ¡£

¶ÔÓÚIDE¿ÉÒÔÕâô±ÈÓ÷£¬ËüºÃÏóÊÇ·É»úÉϵÄ×Ô¶¯¼ÝÊ»ÒÇ£¬ÓÐÁËËü·ÉÐÐÔ±»áÇáËÉÐí¶à£¬µ«Èç¹û·ÉÐÐԱûÓÐÕæÕýÕÆÎÕ·É»úµÄ¼ÝÊ»¼¼Êõ£¬ÔÚ·ÉÐÐÖÐÈç¹û×Ô¶¯¼ÝÊ»ÒÇʧÁéµÄ»°£¬×¹»úÊDZØÈ»µÄ£¬ÕâÑùµÄ·ÉÐÐÔ±ÊDz»ÄÜÈÃËû¼Ý»úµÄ¡£±à³ÌÈËÔ±Ò²Èç´Ë£¬Ö»ÓÃIDE¿ª·¢Èí¼þÊDz»¹»µÄ¡£

¿ªÊ¼¶¯ÊÖ

×ø̸ÂÛµÀ²»ÈçÆð¶ø¹ªÐС£ÏÂÃæ¾Í´ÓÒ»¸ö¼òµ¥µÄCÓïÑÔÔ´ÎļþµÄ±àÒ뿪ʼ£¬Ñо¿ÕâЩÄÚÈÝ¡£

Ê×ÏÈÊÇ°²ÅźÃĿ¼¡£ÔÚ×Ô¼ºµÄÓû§Ä¿Â¼Ï£¬´´½¨Ò»¸ö×ܵÄĿ¼learn-gnu£¬È»ºóÔÚ´ËĿ¼Ï´´½¨µÚÒ»¸öѧϰĿ¼learn-1£¬ÔÚ´ËĿ¼ÏÂÓÃEmacs±à¼­hello.cÎļþ£¬ÊäÈëÈçÏÂÄÚÈÝ£º

ÒýÓÃ:
//hello.c
#include
int main(int argc, char *argv[])
{
int i;

if(argc<=1)
{
printf("The program name is :%s\n", argv[0]);
}
else
{
printf("The program name is :%s\n", argv[0]);
for(i=1; i
printf("The argument %d is : %s\n", i, argv[i]);
}
}




Õâ¶Î´úÂëÊÔÑéÁËÃüÁîÐвÎÊý¼°Æä¼òµ¥µÄÓ÷¨£¬Õý³£Çé¿öÏÂÔÚÖÕ¶ËÖÐÊäÈëÏÂÃæµÄÃüÁî¼´¿É±àÒë:

# gcc hello.c -o hello



±àÒëºóÊä³ö¿ÉÖ´ÐÐÎļþhello£¬Ö´ÐÐ./hello¼´¿ÉÊä³öÏÂÃæµÄÓï¾ä£º

The program name is :./hello



ÕâÊÇCÓïÑÔ³õѧÕßѧµ½µÄ×î¼òµ¥¡¢×îԭʼ¡¢×îÖ±½Ó¡¢Ò²ÊÇ×îÓÐЧµÄ±àÒë·½·¨£¬²âÊÔ·½·¨Ò²ÊÇ×î¼òµ¥µÄ¡£ÒòΪËù¸øÓÃÀýµÄ´úÂëÒ²±È½Ï¼òµ¥£¬²»ÓÃÌ«¸´Ôӵķ½·¨¡£

ÕâÀïûÓÐÓúܾ­µäµÄ¡°Hello world¡±³ÌÐò£¬ÆäÔ­ÒòÊDZÊÕßÔÚ¸¨µ¼Ò»Ð©Ñ§ÉúÃÇѧϰCÓïÑԿγÌʱ£¬·¢ÏÖËûÃǶÔÕâ¸ö³ÌÐò»¹²»Ì«Àí½â¡£

ÓÐûÓиüºÃµÄ°ì·¨À´±àÒëÕâ¸öÔ´³ÌÐòÄØ£¿¿ÉÒÔ±àдһ¸ö¼òµ¥µÄMakefileÎļþ£¬Ê¹Ö®×Ô¶¯±àÒëÔ´³ÌÐò£¬Éú³É¿ÉÖ´ÐÐÎļþ£¬±í1ΪMakefileÎļþµÄÄÚÈÝ¡£

CC = gcc ÆäÖÐÖ´ÐÐmake»òmake all¼´Ö´ÐÐall:
all: hello.c ºóÃæµÄÃüÁ¼´±àÒ룻
$(CC) hello.c -o hello make clean ¾ÍÖ´ÐÐclean:ºóÃæµÄÃüÁ
clean: ¼´Çå³ý±àÒë½á¹û¡£
rm hello -f



ÓÃEmacs±à¼­Ëü²¢ºÍÉÏÃæµÄhello.c±£´æµ½Í¬Ò»ÎļþĿ¼£¬×¢ÒâÎļþÃûΪMakefile£¬È»ºó£¬ÔÚÖÕ¶ËÖÐÊäÈëmakeÃüÁ´Ëʱ»á³öÏÖÏÂÃæµÄÇé¿ö£º

# make
# gcc hello.c -o hello



ÔÙÖ´ÐÐÁÐĿ¼ÃüÁ»á·¢ÏÖÒÑÉú³É¿ÉÖ´ÐÐÎļþhello£º

# ls
hello hello.c Makefile



ÏÂÃæÊǶà¸ö²ÎÊýµÄÊä³ö½á¹û£¬ÏàÐÅ»á¶ÔÃüÁîÐвÎÊýÓгõ²½µÄÁ˽⡣

# ./hello abc def 123
The program name is :./hello
The argument 1 is : abc
The argument 2 is : def
The argument 3 is : 123



MakefileÊÇMake¹¤¾ßĬÈϵÄÅäÖÃÎļþ£¬Ö´ÐÐmakeÃüÁîʱ£¬Make×Ô¶¯²éÕÒMakefileÎļþ¡£Óöà¸öCÓïÑÔÔ´ÎļþÀ´±àÒëʱ£¬Ê¹ÓÃMake»áÈñàÒë¹ý³Ì¸ü¼Ó¿ì½ÝÓÐЧ¡£ÒòΪMakeÊÇ°´Ô´ÎļþµÄ¸üÐÂʱ¼äÅжÏÊÇ·ñ½øÐбàÒëµÄ£¬¼´¸Ä¶¯ÁËÄĸöÎļþ¾Í±àÒëÄĸöÎļþ£¬Î´¸Ä¶¯µÄ¾Í²»×ö´¦Àí¡£

ÕâÀïÒÔÒ»¸öÉÔ¸´ÔÓµÄÀý×ÓÀ´ËµÃ÷¡£Ò»¸öÏîÄ¿ÓÉÈý¸öCÓïÑÔÔ´Îļþa.c¡¢b.cºÍhello.h¹¹³É£¬ÆäÖÐa.cºÍb.cÖж¼°üº¬hello.h£¬×îÖÕÊä³öµÄ¿ÉÖ´ÐÐÎļþΪhello¡£±í2ΪÕâ¸öMakefileÎļþµÄÄÚÈÝ¡£

Ïë½øÒ»²½Ñ§Ï°MakeµÄʹÓúÍMakefileÎļþµÄ±àд£¬¿ÉÒÔ¿´Ò»ÏÂËüµÄ²Î¿¼Îĵµ£¬ÍøÖ·ÊÇhttp://www.gnu.org/manual/make-3.79.1/html_chapter/make_toc.html¡£

Èç¹ûÔ´³ÌÐòÔÙ¸´ÔÓһЩ£¬ÀýÈç¶àһЩԴÎļþºÍ¸½¼ÓÒ»¶¨ÊýÁ¿µÄ×ÊÔ´£¨ÈçͼÏñºÍÎĵµµÈ£©£¬»òÕßÉæ¼°µ½ÏµÍ³ÖеÄÆäËüÖ§³Ö£¨ÈçÐèҪϵͳ°²×°ÓÐÎĵµ´¦Àí¹¤¾ß£¬Óï·¨¼ì²â¹¤¾ß£¬Ä³Ð©¿ª·¢¹¤¾ßµÄ¿ª·¢¿âµÈ£©Ê±£¬ÔÙ±àдMakefileÎļþ¾Í»á±äµÃ·Ç³£Âé·³£¬Ò²·Ç³£ÈÝÒ׳ö´í¡£ÕâÖÖÇé¿ö¿ÉÒÔʹÓÃAutoconf ¡¢AutomakeºÍLibtoolµÈ¹¤¾ßÀ´Íê³ÉÕâÒ»¹¤×÷£¬ÕâÈÃMakefileÓиü¶àµÄ¹¦ÄÜ£¬±àÒë¸ü¼ÓÍ걸£¬¼ì²â¸ü¼ÓÈ«Ã棬¶øÇÒ»¹¶à³öÁË°²×°¡¢´ò°ü·¢²¼µÈ¸ü¶àй¦ÄÜ
ÎÄÕÂÆÀÂÛ

¹²ÓÐ 0 ÌõÆÀÂÛ