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

你可能感兴趣的文章
openssl在cygwin下编译错误:CPU不支持x86_64(CPU you selected does not support x86-64 instruction set )
查看>>
openssl安装
查看>>
openssl安装
查看>>
OpenSSL生成root CA及签发证书
查看>>
Openstack CLI命令管理私有云主机实战(附OpenStack实验环境)
查看>>
openStack instance error 恢复
查看>>
openstack instance resize to
查看>>
openstack message queue
查看>>
openstack network:dhcp binding fail
查看>>
openStack openSource CloudComputing
查看>>
Openstack REST API
查看>>
OpenStack ussuri 私有云平台搭建企业级实战
查看>>
OpenStack 上部署 Kubernetes 方案对比
查看>>
Openstack 之 网络设置静态IP地址
查看>>
openstack 创建虚拟机的时候报错: Failed to allocate the network(s), not rescheduling.].
查看>>
OpenStack 存储服务详解
查看>>
openstack 导出镜像
查看>>
OpenStack 搭建私有云主机实战(附OpenStack实验环境)
查看>>
OpenStack 综合服务详解
查看>>
OpenStack 网络服务Neutron技术内幕
查看>>