博客
关于我
Linux系统编程25:基础IO之亲自实现一个动静态库
阅读量:193 次
发布时间:2019-02-28

本文共 1459 字,大约阅读时间需要 4 分钟。

??

???????????????.a?.so???????.a?.so???????.o????????????????.o?????????????????

?????????????mylib.h????mylib.c?????????????????????

// mylib.h#include 
void Myprintf();
// mylib.c#include "mylib.h"void Myprintf() {    printf("Hello World\n");}

????gcc -c??.o???????????test??mylib.o?mylib.h?????????????????????test.c????????????mylib.h?????Myprintf??????????????mylib.o???

?????

??????????????????????????????????????add.c add.h sub.c sub.h?????

?????????

// add.h#include 
int add(int x, int y);
// add.c#include "add.h"int add(int x, int y) {    return x + y;}
// sub.h#include 
int sub(int x, int y);
// sub.c#include "sub.h"int sub(int x, int y) {    return x - y;}

??????.c????????.o???????ar -rc????????

ar -rc libMYLIB.a add.o sub.o

????????????.a????????????????????my_method?????include?lib??????.h?????include?????.a?????lib????

?????

????????????????Makefile????????????-fPIC????????????????-shared??????????

Makefile?????

libMYLIB.so: add.o sub.o    gcc -shared -o $@ $^add.o: add.c    gcc -fPIC -c add.csub.o: sub.c    gcc -fPIC -c sub.cclean:    rm -rf *.o libMYLIB.so my_methodpackage:    mkdir -p my_method/include    mkdir -p my_method/lib    cp *.h my_method/include    cp *.so my_method/lib

?????????????????????????-static???

gcc -o test.exe test.c -I./my_method/include -L./my_method/lib -lMYLIB

????????????????????????????LD_LIBRARY_PATH????????

export LD_LIBRARY_PATH=./my_method/lib

????????????????????

转载地址:http://ojsi.baihongyu.com/

你可能感兴趣的文章
Oracle 11g 数据类型
查看>>
Oracle 11g 编译使用BBED
查看>>
oracle 11g 静默安装
查看>>
Oracle 11gR2学习之二(创建数据库及OEM管理篇)
查看>>
Oracle 11gR2构建RAC之(2)--配置共享存储
查看>>
Oracle 11g中的snapshot standby特性
查看>>
Oracle 11g关闭用户连接审计
查看>>
Oracle 11g忘记sys、system、scott密码该这样修改!
查看>>
Oracle 11g数据库安装和卸载教程
查看>>
Oracle 11g数据库成功安装创建详细步骤
查看>>
Oracle 11g超详细安装步骤
查看>>
Oracle 12c中的MGMTDB
查看>>
Oracle 12c安装报错Installation failed to access the temporary location(无法访问临时位置)...
查看>>
Oracle 9i数据库管理教程
查看>>
ORACLE Active dataguard 一个latch: row cache objects BUG
查看>>
oracle avg、count、max、min、sum、having、any、all、nvl的用法
查看>>
Oracle BEQ方式连接配置
查看>>
oracle Blob保存方式,oracle 存储过程操作blob
查看>>
Oracle BMW Racing sailing vessel帆船图
查看>>
ORACLE Bug 4431215 引发的血案—原因分析篇
查看>>