BBS水木清华站∶精华区

发信人: Hanky.bbs@cis.nctu.edu.tw (专收破烂的小阿吉), 看板: Linux 
标  题: Re: 如何来做自己的library file? 
发信站: 交大资科_BBS (Tue Oct 29 17:53:51 1996) 
转信站: JoeLu!netnews.ntu!linux2.tpml!UUserv.Net.tw!news.cis.nctu!cisnews.cis. 
 
==> 在 Apple_C.pbbs@pbbs.chpi (Apple C) 的文章中提到: 
 as title !! 
   我想自己来做一个library file !!可是不知道如何做..可有参考资料.. 
   烦请告知!!谢谢!! 
 
for ELF only......我转贴一封老外的 post 好了。 
 
   ==================================================================== 
You no longer need the DLL tools. Suppose I 
want to create "libmine.so.1.6", from the files: 
  foo.c bar.c qux.c 
 
Step 1: Compile as PIC (旧 a.out 是 pic) 
 
  % gcc -c -fPIC foo.c 
  % gcc -c -fPIC bar.c 
  % gcc -c -fPIC qux.c 
 
Step 2: Link into shared libarary. 
 
  % gcc -shared -Wl,-soname,libmine.so.1 -o libmine.so.1.6 foo.o bar.o qux.o 
                            ^^^^^^^^^^^^你的 so name, 含 major version 
 
Step 3: Install 
 
  % su root 
  # cp libmine.so.1.6 /usr/local/lib 
  # chmod u=rw,g=r,o=r /usr/local/lib/libmine.so.1.6 
  # /sbin/ldconfig -v 
 
 

BBS水木清华站∶精华区