Linux--静态库、动态库

我们先简单的编写了一个add.c   sub.c  add.o   sub.o main.c 函数

 1 #include "add.h"
  2 
  3 int add(int a,int b)
  4 {
  5   return a+b;
  6 }
  1 #include "sub.h"
  2 
  3 int sub(int a,int b)
  4 {
  5  return a-b;
  6 }
  1 #ifdef __SUB_H
  2 #define __SUB_H
  3 int sub(int a,int b)
  4 
  5 #endif
  1 #ifndef __ADD_H
  2 #define __ADD_H
  3 
  4 int add(int a,int b);
  5 
  6 #endif
  1 #ifndef __ADD_H
  2 #define __ADD_H
  3 
  4 int add(int a,int b);
  5 
  6 #endif
  1 #include<stdio.h>
  2 #include "add.h"
  3 #include "sub.h"
  4 
  5 int main()
  6 {
  7 int a=10;
  8 int b=2;
  9 printf("%d+%d=%d\n",a,b,a+b);
 10 printf("%d-%d=%d\n",a,b,a-b);
 11 }

一、静态库(快)

            .o  的文件集合

            如何制作?

                    ar -rc lib***.a  .o

                    lib***  : 静态文件名

                    ****  :静态库名


                 如何使用?
                        -l 库名
                寻找库
                        -L 指定库的位置

                    

二、动态库(节省内存)
        制造动态库
        gcc -fPIC(位置无关) -shared -o lib***.so *.c
        编译
        gcc main.c -L. -l***

        运行动态库
        (1) /lib
        /user/lib
        (2)export LD_LIBRARY_PATH =.(指定到当前位置)
         (3) /etc/ld.so.conf.d/***.conf
        ldconfig 刷新缓存






  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值