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

¾²Ì¬¿âºÍ¶¯Ì¬¿â----linux³ÌÐòÉè¼Æ֮·

·¢²¼Ê±¼ä:2008-03-02 15:44:51À´Ô´:ºìÁª×÷Õß:pplicat
×î½üÕýÔÚѧϰlinux»·¾³ÏµijÌÐòÉè¼Æ£¬Í¾Öлá°Ñ×Ô¼ºµÄѧϰÐĵÃдÉÏÀ´£¬²»×ãÖ®´¦Ï£Íû´ó¼ÒÖ¸³ö¡£

linuxÖÐÓÐÁ½ÀຯÊý¿â£¬·Ö±ðÊǾ²Ì¬¿âºÍ¶¯Ì¬¿â¡£

¾²Ì¬º¯Êý¿â£º
ÕâÀà¿âµÄÃû×ÖÒ»°ãÊÇlibxxx.a£»ÀûÓþ²Ì¬º¯Êý¿â±àÒë³ÉµÄÎļþ±È½Ï´ó£¬ÒòΪÕû¸öº¯Êý¿âµÄËùÓÐÊý¾Ý¶¼»á±»ÕûºÏ½øÄ¿±ê´úÂëÖУ¬ËûµÄÓŵã¾ÍÏÔ¶øÒ×¼ûÁË£¬¼´±àÒëºóµÄÖ´ÐгÌÐò²»ÐèÒªÍⲿµÄº¯Êý¿âÖ§³Ö£¬ÒòΪËùÓÐʹÓõĺ¯Êý¶¼ÒѾ­±»±àÒë½øÈ¥ÁË¡£µ±È»ÕâÒ²»á³ÉΪËûµÄȱµã£¬ÒòΪÈç¹û¾²Ì¬º¯Êý¿â¸Ä±äÁË£¬ÄÇôÄãµÄ³ÌÐò±ØÐëÖØбàÒë¡£

¶¯Ì¬º¯Êý¿â£º
ÕâÀà¿âµÄÃû×ÖÒ»°ãÊÇlibxxx.so;Ïà¶ÔÓÚ¾²Ì¬º¯Êý¿â£¬¶¯Ì¬º¯Êý¿âÔÚ±àÒëµÄʱºò²¢Ã»Óб»±àÒë½øÄ¿±ê´úÂëÖУ¬ÄãµÄ³ÌÐòÖ´Ðе½Ïà¹Øº¯Êýʱ²Åµ÷Óøú¯Êý¿âÀïµÄÏàÓ¦º¯Êý£¬Òò´Ë¶¯Ì¬º¯Êý¿âËù²úÉúµÄ¿ÉÖ´ÐÐÎļþ±È½ÏС¡£ÓÉÓÚº¯Êý¿âûÓб»ÕûºÏ½øÄãµÄ³ÌÐò£¬¶øÊdzÌÐòÔËÐÐʱ¶¯Ì¬µÄÉêÇë²¢µ÷Óã¬ËùÒÔ³ÌÐòµÄÔËÐл·¾³ÖбØÐëÌṩÏàÓ¦µÄ¿â¡£¶¯Ì¬º¯Êý¿âµÄ¸Ä±ä²¢²»Ó°ÏìÄãµÄ³ÌÐò£¬ËùÒÔ¶¯Ì¬º¯Êý¿âµÄÉý¼¶±È½Ï·½±ã¡£

linuxϵͳÓм¸¸öÖØÒªµÄĿ¼´æ·ÅÏàÓ¦µÄº¯Êý¿â£¬Èç/lib /usr/lib¡£

ÏÂÃæÀ´½éÉÜlinux¾²Ì¬º¯Êý¿âµÄ´´½¨ºÍʹÓãº

Àý³Ìstr_out.h str_out.c main.c:

ÒýÓÃ:
str_out.h

#ifndef STR_OUT_H
#define STR_OUT_H
void str_out(const char* str);
#endif

str_out.c

#include
#include "str_out.h"
void str_out(const char* str){
printf("%s\n",str);
}

main.c

int main()
{
str_out("hello world");
return 0;
}


²»¹ÜÊǾ²Ì¬º¯Êý¿â»¹ÊǶ¯Ì¬º¯Êý¿â£¬¶¼ÊÇÓÉ*.oÄ¿±êÎļþÉú³É¡£

ËùÒÔÏÈgcc -c str_out.c

¾²Ì¬º¯Êý¿âÓÉarÃüÁî´´½¨
±¾Àý£ºar -cr libstr_out.a str_out.o

-c createµÄÒâ˼

-r replaceµÄÒâ˼£¬±íʾµ±²åÈëµÄÄ£¿éÃûÒѾ­ÔÚ¿âÖдæÔÚ£¬ÔòÌ滻ͬÃûµÄÄ£¿é¡£Èç¹ûÈô¸ÉÄ£¿éÖÐÓÐÒ»¸öÄ£¿éÔÚ¿âÖв»´æÔÚ£¬arÏÔʾһ¸ö´íÎóÏûÏ¢£¬²¢²»Ìæ»»ÆäËûͬÃûÄ£¿é¡£Ä¬ÈϵÄÇé¿öÏ£¬ÐµijÉÔ±Ôö¼ÓÔÚ¿âµÄ½áβ´¦£¬¿ÉÒÔʹÓÃÆäËûÈÎÑ¡ÏîÀ´¸Ä±äÔö¼ÓµÄλÖá£

µ½´Ë¾²Ì¬º¯Êý¿â´´½¨Íê±Ï¡£

ʹÓ÷½·¨£ºÍ¨¹ýgcc -o out main.c -L. -lstr_out±àÒëmain.c¾Í»á°Ñ¾²Ì¬º¯Êý¿âÕûºÏ½øout¡£

ÆäÖÐ
-LÖ¸¶¨¾²Ì¬º¯Êý¿âµÄλÖù©²éÕÒ£¬×¢ÒâLºóÃ滹ÓÐ'.'£¬±íʾ¾²Ì¬º¯Êý¿âÔÚ±¾Ä¿Â¼Ï²éÕÒ¡£

-lÔòÖ¸¶¨Á˾²Ì¬º¯Êý¿âÃû£¬ÓÉÓÚ¾²Ì¬º¯Êý¿âµÄÃüÃû·½Ê½ÊÇlib***.a£¬ÆäÖеÄlibºÍ.aºöÂÔ¡£

¸ù¾Ý¾²Ì¬º¯Êý¿âµÄÌØÐÔ£¬´Ë´¦É¾³ýlibstr_out.aºóoutÒÀÈ»¿ÉÒÔÔËÐУ¬ÒòΪ¾²Ì¬¿âµÄÄÚÈÝÒѾ­ÕûºÏ½øÈ¥ÁË¡£

¶¯Ì¬º¯Êý¿âµÄ´´½¨ºÍʹÓÃ
gcc -shared -fPCI -o out main.c -L. -lstr_out

ÓøÃÃüÁîÉú³Élibstr_out.so ¶¯Ì¬º¯Êý¿â¡£

gcc -o out main.c

´Ëʱ»¹²»ÄÜÁ¢¼´./out£¬ÒòΪÔÚ¶¯Ì¬º¯Êý¿âʹÓÃʱ£¬»á²éÕÒ/usr/lib /libĿ¼ÏµĶ¯Ì¬º¯Êý¿â£¬¶ø´ËʱÎÒÃÇÉú³ÉµÄ¿â²»ÔÚÀï±ß¡£

Õâ¸öʱºòÓкü¸ÖÖ·½·¨¿ÉÒÔÈÃËû³É¹¦ÔËÐУº

×îÖ±½Ó×î¼òµ¥µÄ·½·¨¾ÍÊÇ°Ñlibstr_out.soÀ­µ½/usr/lib »ò/libÖÐÈ¥¡£

»¹ÓÐÒ»ÖÖ·½·¨ export LD_LIBRARY_PATH=$(pwd)

ÁíÍ⻹¿ÉÒÔÔÚ/etc/ld.so.confÎļþÀï¼ÓÈëÎÒÃÇÉú³ÉµÄ¿âµÄĿ¼£¬È»ºó/sbin/ldconfig¡£

/etc/ld.so.confÊǷdz£ÖØÒªµÄÒ»¸öĿ¼£¬ÀïÃæ´æ·ÅµÄÊÇÁ´½ÓÆ÷ºÍ¼ÓÔØÆ÷ËÑË÷¹²Ïí¿âʱҪ¼ì²éµÄĿ¼£¬Ä¬ÈÏÊÇ´Ó/usr/lib /libÖжÁÈ¡µÄ£¬ËùÒÔÏëҪ˳ÀûÔËÐУ¬ÎÒÃÇÒ²¿ÉÒÔ°ÑÎÒÃÇ¿âµÄĿ¼¼ÓÈëµ½Õâ¸öÎļþÖв¢Ö´ÐÐ/sbin/ldconfig

ÁíÍ⻹ÓиöÎļþÐèÒªÁ˽â/etc/ld.so.cache,ÀïÃæ±£´æÁ˳£ÓõĶ¯Ì¬º¯Êý¿â£¬ÇÒ»áÏÈ°ÑËûÃǼÓÔص½ÄÚ´æÖУ¬ÒòΪÄÚ´æµÄ·ÃÎÊËÙ¶ÈÔ¶Ô¶´óÓÚÓ²Å̵ķÃÎÊËٶȣ¬ÕâÑù¿ÉÒÔÌá¸ßÈí¼þ¼ÓÔض¯Ì¬º¯Êý¿âµÄËÙ¶ÈÁË¡£
ÎÄÕÂÆÀÂÛ

¹²ÓÐ 5 ÌõÆÀÂÛ

  1. swarron ÓÚ 2010-05-15 12:02:46·¢±í:

    pass

  2. glxin1982 ÓÚ 2010-05-14 17:37:38·¢±í:

    ѧϰÁË£¬Ð»Ð»

  3. ericq2010 ÓÚ 2010-05-14 11:39:08·¢±í:

    ѧϰѧϰ

  4. wfbaaa ÓÚ 2008-03-03 18:15:50·¢±í:

    ѧϰÁË£¬Ð»Ð»

  5. redheroak ÓÚ 2008-03-03 15:36:29·¢±í:

    (6)m:b Ö§³ÖÒ»ÏÂ