博客
关于我
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 面向对象 final类与final方法
查看>>
php+JQ+EasyUI自动加载数据
查看>>
php+sql server根据自增序号id区间查询第几条到第几条的数据
查看>>
php--------获取当前时间、时间戳
查看>>
Redis使用场景举例
查看>>
php--正则表达式
查看>>
php--防止sql注入的方法
查看>>
PHP-CGI Windows平台远程代码执行漏洞复现(CVE-2024-4577)
查看>>
php-cgi耗尽报502错误
查看>>
php-cgi(fpm-cgi) 进程 CPU 100% 与 file_get_content...
查看>>
PHP-DI/Invoker 开源项目使用教程
查看>>
php-fpm与Nginx运行常见错误说明
查看>>
php-fpm比php成为apache模块好在哪
查看>>
php-fpm超时时间设置request_terminate_timeout分析
查看>>
php-fpm进程数优化
查看>>
PHP-GD库-分类整理
查看>>
php-laravel框架用户验证(Auth)模块解析(一)
查看>>
php-laravel框架用户验证(Auth)模块解析(三)登录模块
查看>>
php-laravel框架用户验证(Auth)模块解析(二)注册模块
查看>>
php-laravel框架用户验证(Auth)模块解析(四)忘记密码
查看>>