????8.???°?????????????????????????
????????????/lib????/usr/lib?£????ld?????????????????????????
???????????????????????????????/etc/ld.so.cache????У?????????
????step1.??/etc/ld.so.conf?????????????????????·??
????step2.????ldconfig????????????/etc/ld.so.cache???
????9.????????t???????
??????????????Щ???ú??????????????????????????á????????????????????????????????????????????????????У????????????????????t????????????????????????????????????У??????????????????????????????????????????????????????????????????????Linux????δ?????????????????????????????????????????????????????????????????????????????????.o?????
??????1??????????????????--hello.h??hello.c??main.c??
????hello.h(??????1)??ú????????????
????hello.c(??????2)????????????????а??????ú???hello???ú???????????????"Hello XXX!"??
????main.c(??????3)??????????????????????????е???????ú???hello??

 

????1: hello.h
#ifndef HELLO_H
#define HELLO_H
void hello(const char *name);
#endif //HELLO_H
????2: hello.c
#include
void hello(const char *name)
{
printf("Hello %s! "?? name);
}
????3: main.c
#include "hello.h"
int main()
{
hello("everyone");
return 0;
}
??????2??????hello.c?????.o?????
??????????????????????????.o??????????????????????????hello.c???gcc??????.o?????
????????????????????????????hello.o?????
????# gcc -c hello.c
????#
????(?1??????????????????ú?????????????????????????????ο??????????)
????(?2???????"#"?????????????????????????????)
????????????ls???????????????hello.o?????
????# ls
????hello.c hello.h hello.o main.c
????#
????(?3???????????"#"??????н?????????????)
??????ls???????У??????????hello.o???????????????ɡ?
??????????????????????δ??????????????????
??????3??????.o????????????
?????????????????????淶????lib??????????????????????????.a?????磺??????????????????myhello??????????????libmyhello.a???????????t???????????????????????????ar???
??????????????????????????????????????libmyhello.a??
????# ar cr libmyhello.a hello.o
????#
???????????????ls??????????
????# ls
????hello.c hello.h hello.o libmyhello.a main.c
????#
????ls??????????libmyhello.a??
??????4?????????????t????
?????????????????????????????????????????????????Щ???ú???????????а?????Щ???ú?????????????????????gcc???????????????????????????gcc??????????н????ú???????????????С????gcc?????????????????lib?????????????.a?????????????????????????????
?????????3:main.c?У???????????????????hello.h?????????????main???????ù??ú???hello??
????????????????????hello?????????hello???????????Ρ?
????# gcc -o hello main.c -L. -l myhello
????# ./hello
????Hello everyone!
????#
?????????????????????????ú???hello????????????????? hello?????
????# rm libmyhello.a
????rm: remove regular file `libmyhello.a'? y
????# ./hello
????Hello everyone!
????#
??????????????У???????е???ú??????????????????????
????????????????????Linux?д????????????????.o????????
???????????????????????漰???????????????????SPASVOС??(021-61079698-8054)?????????????????????????