生成so的makefile和测试这个so的makefile

1.生成so的代码由max.h和max.c组成.
//max.h

#ifndef _MAX_H
#define _MAX_H

int max(int a, int b);

#endif

//max.c
#include "max.h"
#include "stdio.h"

int max(int a, int b)
{
    return (a > b ? a : b);
}

用下面这个命令生成so文件

gcc -shared max.c -o libmax.so; cp libmax.so /usr/lib

或者:gcc -shared max.c -o libmax.so


2.测试so的例子
//test_so.c
#include "stdio.h"
#include "max.h"

int main(int argc, char **argv)
{
    printf("test so max=%d\n", max(1,2));
    return 0;
}

用下面这个命令来生成可执行程序

gcc -lmax test_so.c -o test_so

或者:gcc -lm ./libmax.so test_so.c -o test_so

./test_so即可得到测试结果.

                                                                                                                         

>>一个最简单的方式:你把编译命令写进Makefile就可以了
>>如果想找一个复杂的,直接看Linux下面的so库程序源代码就可以了


转载地址:

http://bbs.chinaunix.net/thread-2166323-1-1.html


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值