博客
关于我
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/

你可能感兴趣的文章
Python pip工具使用
查看>>
Python pip配置国内源
查看>>
Python Plotly 将轴数格式化为 %
查看>>
Redis 键值过期操作
查看>>
python predictabel_基于R语言PredictABEL包对Logistic回归模型外部验证
查看>>
Python psycopg2 超时
查看>>
Python Pyinstaller Matplotlibrary
查看>>
Python Pypi 修改 国内源(以豆瓣源为例)
查看>>
Python PyQt5 将不再显示此消息复选框添加到 QMessageBox
查看>>
Python PyQt5:如何使用 PyQt5 显示错误消息
查看>>
Python PYSFTP-以字符串/文本形式传递私钥,而不是传递文件路径
查看>>
Python pytest 面试题!
查看>>
Python pytz 时区函数返回一个相差 9 分钟的时区
查看>>
python rabbitmq实现简单/持久/广播/组播/topic/rpc消息异步发送可配置Django
查看>>
Python random和json模块
查看>>
Python random模块seed理解
查看>>
python range()函数
查看>>
Python rdflib可传递查询
查看>>
Redis 配置高可用和搭建集群
查看>>
python redis 集群_python 搭建redis集群
查看>>