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

你可能感兴趣的文章
PHP使用3DES算法加密解密字符串
查看>>
PHP使用curl multi要注意的问题:每次使用curl multi同时并发多少请求合适
查看>>
php使用memcached扩展的一个BUG
查看>>
SpringBoot基础教程2-1-11 RestTemplate整合HttpClient
查看>>
PHP入门part1
查看>>
PHP兼容性检查,PHP升级语法检查(PHPCompatibility+PHP_CodeSniffer)
查看>>
PHP内核介绍及扩展开发指南—基础知识
查看>>
php内核基础说明
查看>>
PHP写日志fwrite和file_put_contents的区别与性能
查看>>
PHP写计划任务
查看>>
PHP出现Notice: unserialize() [function.unserialize]: Error at offset问题的解决方案
查看>>
PHP函数
查看>>
React input defaultValue不会更新状态怎么办?
查看>>
PHP函数__autoload失效原因(与smarty有关)
查看>>
PHP函数判断移动端和PC端
查看>>
Springboot基础入门
查看>>
php函数性能优化中应注意哪些问题?
查看>>
PHP函数操作数字和汉字互转(100以内)
查看>>
PHP函数方法
查看>>
PHP创建目录mkdir无写入权限的问题解决方案
查看>>