⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 1024.html

📁 著名的linux英雄站点的文档打包
💻 HTML
📖 第 1 页 / 共 2 页
字号:
                          <DIV align=center>
                        <FORM action="search.html" tppabs="http://www.linuxhero.com/docs/search.html" method=get>
                            </FORM>
                        <TABLE cellSpacing=0 cellPadding=0 width="95%" 
                          border=0><TBODY>
                          <TR>
                            <TD background="images/bgi.gif" tppabs="http://www.linuxhero.com/docs/images/bgi.gif" 
                          height=30></TD></TR></TBODY></TABLE>
                        <TABLE cellSpacing=0 cellPadding=3 width="95%" 
                        align=center border=0>
                          <TBODY>
                          <TR>
                            <TD>
                              <TABLE cellSpacing=0 cellPadding=3 width="100%" 
                              border=0>
                                <TBODY>
                                <TR>
                                      <TD vAlign=top> 
<p><FONT class=normalfont><B><font color=blue>生成静态连接库</font></B></FONT><BR><FONT class=smallfont color=#ff9900>2004-04-23 15:18 pm</FONT><BR><FONT class=normalfont>作者:作者<br>来自:Linux知识宝库<br>联系方式:无名<br><br>静态库及动态库的建立 <br>
UNIX系统及各种软件包为开发人员提供了大量的库文件。但一般情况下这些库文件还 <br>
不能足以满足用户的所有需求。开发人员大多会根据他们自己的开发、研究要求编写 <br>
出许多函数。对于这些函数,如果都用在命令行中指定源文件的方法同调用它们的程 <br>
序链接起来,虽然也是可以的,但也有一些缺点: <br>
..... <br>
<br>
下面来看看如何生成静态库。 <br>
我们知道静态库也称档案库,在此档案文件中实际上是收集了一系列的目标文件。这 <br>
些目标文件就是由cc(gcc)函数的源代码编译生成的。因此,静态库的生成方法实际上 <br>
可以分成两步: <br>
1.将各函数代码所在的源文件编译成目录文件。例如,对于myfunc.c,可以用如下命令 <br>
将其编译成目标文件: <br>
        gcc -c myfunc.c <br>
当然在有多个源文件时,只需在gcc 命令行中将其分别列上就可以了。 <br>
经此一步我休养将能够得到各源文件的目标文件。对上例,将得到myfunc.o <br>
2.将各目标文件收集起来放到一个静态库文件中。这主要借助于ar命令完成,如: <br>
        ar r ~/lib/libtest.a myfunc.o <br>
<br>
建立动态链接库、并不需要用到其他的工具,借助于gcc命令即可完成。此时需在命令 <br>
行中加上-K PIC和-G这两个选项,如下我们可以建立libtest的动态版本:        <br>
        gcc -K PIC -G -o $HOME/lib/libtest.so myfunc.c <br>
<br>
<br>
<br>
-- <br>
<br>
发信人: hellguard (小四), 信区: Unix        <br>
标  题: 顺便贴个生成linux动态库的 <br>
发信站: BBS 水木清华站 (Fri Nov 12 10:49:03 1999) <br>
<br>
本来格式很好看的,但因为要贴到这里所以 <br>
扭曲了不少,见谅见谅。这里给的是linux下的例子, <br>
但是solaris下的也差不多,如果你发现不同,就给 <br>
个详细说明出来,好不好。 <br>
<br>
ldd filename就可以看到程序用到哪些库。 <br>
<br>
ld -o OUTPUT /lib/crt0.o hello.o -lc <br>
ld将输出最终结果文件 OUTPUT , <br>
用到/lib/crt0.o hello.o以及libc.a <br>
libc.a来自标准库搜索路径,请参看-l选项的讨论 <br>
<br>
ld的选项顺序任意,可以重复,后面的将覆盖前面的。 <br>
<br>
gcc -c -fPIC linuxlib.c -O3 -o linuxlib.o <br>
gcc -shared -Wl,-soname,liblinuxlib.so.1  <br>
    -O3 -o liblinuxlib.so.1.0 linuxlib.o <br>
( <br>
ld -m elf_i386 -shared -o liblinuxlib.so.1.0  <br>
    -soname liblinuxlib.so.1 linuxlib.o <br>
这个语句产生的文件更小,不知道二者有何区别 <br>
-o liblinuxlib.so.1.0 这个文件名任意,关键是后面 <br>
两个符号连接要正确 <br>
当然推荐使用有意义的带版本信息的名字,包括  <br>
-soname liblinuxlib.so.1 <br>
) <br>
ln -sf liblinuxlib.so.1.0 liblinuxlib.so.1 <br>
(  <br>
    运行时,dynamic linker根据 -soname  <br>
    liblinuxlib.so.1 去寻找liblinuxlib.so.1 <br>
) <br>
ln -sf liblinuxlib.so.1 liblinuxlib.so <br>
(  <br>
    编译的最后一个步骤,ld命令根据 -llinuxlib  <br>
    选项去寻找liblinuxlib.so <br>
) <br>
export LD_LIBRARY_PATH=. <br>
( <br>
    编译时、运行时都需要这个变量的存在 <br>
    编译时如果不存在这个变量,编译依旧通过,但 <br>
    用ldd查看会发现没有动态连接信息 <br>
    运行时如果不存在这个变量,将报告无法找到动态连接库 <br>
<br>
    这个变量如果不用相对路径".",换了运行环境就比较麻烦 <br>
    export LD_LIBRARY_PATH=`pwd`:$LD_LIBRARY_PATH <br>
) <br>
gcc -L. -lbsd -llinuxlib -O3 -o linuxkiller linuxkiller.c <br>
( <br>
    -L. 指出除标准库搜索路径之外的库搜索路径,如果不指 <br>
    定,将找不到liblinuxlib.so <br>
    这个选项并不能代替 LD_LIBRARY_PATH 变量,否则虽然编译通过, <br>
    但用ldd linuxkiller的时候会发现没有动态连接信息 <br>
) <br>
<br>
可以把自己的动态连接库放到/usr/lib或者/lib下去,或者 <br>
修改/etc/ld.so.conf <br>
然后利用/sbin/ldconfig。具体请man ldconfig <br>
<br>
-- <br>
<br>
<br>
发信人: hellguard (小四), 信区: Unix        <br>
标  题: Re: help :static library----what's wrong--Thanks. <br>
发信站: BBS 水木清华站 (Thu Aug 16 14:22:39 2001) <br>
<br>
<br>
【 在 hululu (呼噜噜~回家中) 的大作中提到: 】 <br>
: I am building a static library. But I do not know what is  <br>
: wrong. Below is a sample:  <br>
: tt.c:  <br>
: #include &lt;stdio.h&gt;  <br>
: int func(){  <br>
: printf("func test");  <br>
: return 0;  <br>
: }  <br>
: ii.c:  <br>
: #include &lt;stdio.h&gt;  <br>
: extern int func();  <br>
: ................... <br>
★ 生成静态链接库举例 <br>
<br>
    1. vi demo.h <br>
       void demo ( void ); <br>
<br>
       vi demo.c <br>
       #include &lt;stdio.h&gt; <br>
       #include "demo.h" <br>
       void demo ( void ) <br>
       { <br>
           printf( "hello world" ); <br>
           return; <br>
       } <br>
<br>
    2. g++ -Wstrict-prototypes -Wall -Wunused -O3 -c demo.c -o demo.o <br>
       file demo.o <br>
<br>
    3. ar -rsv libdemo.a demo.o <br>
       a - demo.o <br>
       file libdemo.a <br>
       nm -s libdemo.a <br>
       ar -tv libdemo.a  <br>
    4. vi scz.c <br>
       #include &lt;stdio.h&gt; <br>
       #include "demo.h" <br>
       int main ( int argc, void * argv[] ) <br>
       { <br>
           demo(); <br>
           return 0; <br>
       } <br>
<br>
    5. g++ scz.c -L. -ldemo -Wstrict-prototypes -Wall -Wunused -O3 -o scz <br>
--        (http://www.fanqiang.com)     进入【UNIX论坛】  <br>
--------------------------------------------------------------------------------
</FONT><br>
                                      </TD>
                                    </TR>
                                <TR>
                                <TD colSpan=2><FONT 
                                class=middlefont></FONT><BR>
                                        <FONT 
                                class=normalfont>全文结束</FONT> </TD>
                                    </TR>
                                <TR>
                                <TD background="images/dot.gif" tppabs="http://www.linuxhero.com/docs/images/dot.gif" colSpan=2 
                                height=10></TD></TR></TBODY></TABLE></TD></TR></TBODY></TABLE></DIV></TD>
                        <TD vAlign=top width="20%" 
                      background="images/line.gif" tppabs="http://www.linuxhero.com/docs/images/line.gif" rowSpan=2> 
                          <DIV align=center> 
                            <table class=tableoutline cellspacing=1 cellpadding=4 
                        width="100%" align=center border=0>
                              <tr class=firstalt> 
                                <td noWrap background="images/bgline.gif" tppabs="http://www.linuxhero.com/docs/images/bgline.gif" colspan=2 height=21>
                                <font class=normalfont><b>所有分类</b></font></td>
                              </tr>
<tr class=secondalt> <td noWrap width=27%> <font class=normalfont>1:</font> </td><td noWrap width=73%>   <table width=100% border=0>    <tr>       <td><font class=normalfont><a href="type1.html" tppabs="http://www.linuxhero.com/docs/type1.html">非技术类</a></font></td>    </tr>  </table></td></tr><tr class=firstalt> <td noWrap width=27%> <font class=normalfont>2:</font> </td><td noWrap width=73%>   <table width=100% border=0>    <tr>       <td><font class=normalfont><a href="type2.html" tppabs="http://www.linuxhero.com/docs/type2.html">基础知识</a></font></td>    </tr>  </table></td></tr><tr class=secondalt> <td noWrap width=27%> <font class=normalfont>3:</font> </td><td noWrap width=73%>   <table width=100% border=0>    <tr>       <td><font class=normalfont><a href="type3.html" tppabs="http://www.linuxhero.com/docs/type3.html">指令大全</a></font></td>    </tr>  </table></td></tr><tr class=firstalt> <td noWrap width=27%> <font class=normalfont>4:</font> </td><td noWrap width=73%>   <table width=100% border=0>    <tr>       <td><font class=normalfont><a href="type4.html" tppabs="http://www.linuxhero.com/docs/type4.html">shell</a></font></td>    </tr>  </table></td></tr><tr class=secondalt> <td noWrap width=27%> <font class=normalfont>5:</font> </td><td noWrap width=73%>   <table width=100% border=0>    <tr>       <td><font class=normalfont><a href="type5.html" tppabs="http://www.linuxhero.com/docs/type5.html">安装启动</a></font></td>    </tr>  </table></td></tr><tr class=firstalt> <td noWrap width=27%> <font class=normalfont>6:</font> </td><td noWrap width=73%>   <table width=100% border=0>    <tr>       <td><font class=normalfont><a href="type6.html" tppabs="http://www.linuxhero.com/docs/type6.html">xwindow</a></font></td>    </tr>  </table></td></tr><tr class=secondalt> <td noWrap width=27%> <font class=normalfont>7:</font> </td><td noWrap width=73%>   <table width=100% border=0>    <tr>       <td><font class=normalfont><a href="type7.html" tppabs="http://www.linuxhero.com/docs/type7.html">kde</a></font></td>    </tr>  </table></td></tr><tr class=firstalt> <td noWrap width=27%> <font class=normalfont>8:</font> </td><td noWrap width=73%>   <table width=100% border=0>    <tr>       <td><font class=normalfont><a href="type8.html" tppabs="http://www.linuxhero.com/docs/type8.html">gnome</a></font></td>    </tr>  </table></td></tr><tr class=secondalt> <td noWrap width=27%> <font class=normalfont>9:</font> </td><td noWrap width=73%>   <table width=100% border=0>    <tr>       <td><font class=normalfont><a href="type9.html" tppabs="http://www.linuxhero.com/docs/type9.html">输入法类</a></font></td>    </tr>  </table></td></tr><tr class=firstalt> <td noWrap width=27%> <font class=normalfont>10:</font> </td><td noWrap width=73%>   <table width=100% border=0>    <tr>       <td><font class=normalfont><a href="type10.html" tppabs="http://www.linuxhero.com/docs/type10.html">美化汉化</a></font></td>    </tr>  </table></td></tr><tr class=secondalt> <td noWrap width=27%> <font class=normalfont>11:</font> </td><td noWrap width=73%>   <table width=100% border=0>    <tr>       <td><font class=normalfont><a href="type11.html" tppabs="http://www.linuxhero.com/docs/type11.html">网络配置</a></font></td>    </tr>  </table></td></tr><tr class=firstalt> <td noWrap width=27%> <font class=normalfont>12:</font> </td><td noWrap width=73%>   <table width=100% border=0>    <tr>       <td><font class=normalfont><a href="type12.html" tppabs="http://www.linuxhero.com/docs/type12.html">存储备份</a></font></td>    </tr>  </table></td></tr><tr class=secondalt> <td noWrap width=27%> <font class=normalfont>13:</font> </td><td noWrap width=73%>   <table width=100% border=0>    <tr>       <td><font class=normalfont><a href="type13.html" tppabs="http://www.linuxhero.com/docs/type13.html">杂项工具</a></font></td>    </tr>  </table></td></tr><tr class=firstalt> <td noWrap width=27%> <font class=normalfont>14:</font> </td><td noWrap width=73%>   <table width=100% border=0>    <tr>       <td><font class=normalfont><a href="type14.html" tppabs="http://www.linuxhero.com/docs/type14.html">编程技术</a></font></td>    </tr>  </table></td></tr><tr class=secondalt> <td noWrap width=27%> <font class=normalfont>15:</font> </td><td noWrap width=73%>   <table width=100% border=0>    <tr>       <td><font class=normalfont><a href="type15.html" tppabs="http://www.linuxhero.com/docs/type15.html">网络安全</a></font></td>    </tr>  </table></td></tr><tr class=firstalt> <td noWrap width=27%> <font class=normalfont>16:</font> </td><td noWrap width=73%>   <table width=100% border=0>    <tr>       <td><font class=normalfont><a href="type16.html" tppabs="http://www.linuxhero.com/docs/type16.html">内核技术</a></font></td>    </tr>  </table></td></tr><tr class=secondalt> <td noWrap width=27%> <font class=normalfont>17:</font> </td><td noWrap width=73%>   <table width=100% border=0>    <tr>       <td><font class=normalfont><a href="type17.html" tppabs="http://www.linuxhero.com/docs/type17.html">速度优化</a></font></td>    </tr>  </table></td></tr><tr class=firstalt> <td noWrap width=27%> <font class=normalfont>18:</font> </td><td noWrap width=73%>   <table width=100% border=0>    <tr>       <td><font class=normalfont><a href="type18.html" tppabs="http://www.linuxhero.com/docs/type18.html">apache</a></font></td>    </tr>  </table></td></tr><tr class=secondalt> <td noWrap width=27%> <font class=normalfont>19:</font> </td><td noWrap width=73%>   <table width=100% border=0>    <tr>       <td><font class=normalfont><a href="type19.html" tppabs="http://www.linuxhero.com/docs/type19.html">email</a></font></td>    </tr>  </table></td></tr><tr class=firstalt> <td noWrap width=27%> <font class=normalfont>20:</font> </td><td noWrap width=73%>   <table width=100% border=0>    <tr>       <td><font class=normalfont><a href="type20.html" tppabs="http://www.linuxhero.com/docs/type20.html">ftp服务</a></font></td>    </tr>  </table></td></tr><tr class=secondalt> <td noWrap width=27%> <font class=normalfont>21:</font> </td><td noWrap width=73%>   <table width=100% border=0>    <tr>       <td><font class=normalfont><a href="type21.html" tppabs="http://www.linuxhero.com/docs/type21.html">cvs服务</a></font></td>    </tr>  </table></td></tr><tr class=firstalt> <td noWrap width=27%> <font class=normalfont>22:</font> </td><td noWrap width=73%>   <table width=100% border=0>    <tr>       <td><font class=normalfont><a href="type22.html" tppabs="http://www.linuxhero.com/docs/type22.html">代理服务</a></font></td>    </tr>  </table></td></tr><tr class=secondalt> <td noWrap width=27%> <font class=normalfont>23:</font> </td><td noWrap width=73%>   <table width=100% border=0>    <tr>       <td><font class=normalfont><a href="type23.html" tppabs="http://www.linuxhero.com/docs/type23.html">samba</a></font></td>    </tr>  </table></td></tr><tr class=firstalt> <td noWrap width=27%> <font class=normalfont>24:</font> </td><td noWrap width=73%>   <table width=100% border=0>    <tr>       <td><font class=normalfont><a href="type24.html" tppabs="http://www.linuxhero.com/docs/type24.html">域名服务</a></font></td>    </tr>  </table></td></tr><tr class=secondalt> <td noWrap width=27%> <font class=normalfont>25:</font> </td><td noWrap width=73%>   <table width=100% border=0>    <tr>       <td><font class=normalfont><a href="type25.html" tppabs="http://www.linuxhero.com/docs/type25.html">网络过滤</a></font></td>    </tr>  </table></td></tr><tr class=firstalt> <td noWrap width=27%> <font class=normalfont>26:</font> </td><td noWrap width=73%>   <table width=100% border=0>    <tr>       <td><font class=normalfont><a href="type26.html" tppabs="http://www.linuxhero.com/docs/type26.html">其他服务</a></font></td>    </tr>  </table></td></tr><tr class=secondalt> <td noWrap width=27%> <font class=normalfont>27:</font> </td><td noWrap width=73%>   <table width=100% border=0>    <tr>       <td><font class=normalfont><a href="type27.html" tppabs="http://www.linuxhero.com/docs/type27.html">nfs</a></font></td>    </tr>  </table></td></tr><tr class=firstalt> <td noWrap width=27%> <font class=normalfont>28:</font> </td><td noWrap width=73%>   <table width=100% border=0>    <tr>       <td><font class=normalfont><a href="type28.html" tppabs="http://www.linuxhero.com/docs/type28.html">oracle</a></font></td>    </tr>  </table></td></tr><tr class=secondalt> <td noWrap width=27%> <font class=normalfont>29:</font> </td><td noWrap width=73%>   <table width=100% border=0>    <tr>       <td><font class=normalfont><a href="type29.html" tppabs="http://www.linuxhero.com/docs/type29.html">dhcp</a></font></td>    </tr>  </table></td></tr><tr class=firstalt> <td noWrap width=27%> <font class=normalfont>30:</font> </td><td noWrap width=73%>   <table width=100% border=0>    <tr>       <td><font class=normalfont><a href="type30.html" tppabs="http://www.linuxhero.com/docs/type30.html">mysql</a></font></td>    </tr>  </table></td></tr><tr class=secondalt> <td noWrap width=27%> <font class=normalfont>31:</font> </td><td noWrap width=73%>   <table width=100% border=0>    <tr>       <td><font class=normalfont><a href="type31.html" tppabs="http://www.linuxhero.com/docs/type31.html">php</a></font></td>    </tr>  </table></td></tr><tr class=firstalt> <td noWrap width=27%> <font class=normalfont>32:</font> </td><td noWrap width=73%>   <table width=100% border=0>    <tr>       <td><font class=normalfont><a href="type32.html" tppabs="http://www.linuxhero.com/docs/type32.html">ldap</a></font></td>    </tr>  </table></td></tr>                            </table>
                          </DIV></TD></TR>
                    <TR vAlign=top>
                        <TD width="80%"> 
                          <DIV align=center><BR>
                          </DIV>
                        </TD></TR></TBODY></TABLE></TD></TR>
                </TABLE></TD></TR>
          </TABLE>
      <TABLE cellSpacing=0 cellPadding=4 width="100%" bgColor=#eeeeee 
        border=0><TBODY>
        <TR>
          <TD width="50%">
              <P><FONT class=middlefont>版权所有 &copy; 2004 <A 
            href="mailto:bjchenxu@sina.com">linux知识宝库</A><BR>
                违者必究. </FONT></P>
            </TD>
          <TD width="50%">
              <DIV align=right><FONT class=middlefont>Powered by: <A 
            href="mailto:bjchenxu@sina.com">Linux知识宝库</A> Version 0.9.0 </FONT></DIV>
            </TD></TR></TBODY></TABLE>
      <CENTER></CENTER></TD></TR>
    </TABLE></CENTER></BODY></HTML>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -