交叉编译php-c扩展库(自定义的c扩展)

过程:
0.下载php源码并解压,tar -xjvf PHP 5.3.28 (tar.bz2)
php源码
1.生成扩展骨架:./ext_skel --extname=xianwenjun
2.进入扩展目录: cd xianwenjun
3.编写扩展代码: vim xianwenjun.c
4.修改扩展配置: vim config.m4
5.phpize编译(查看phpize所在路径find / -name phpize查找):
/usr/cneos/buildarm64/ft-yinhe-cross/host/aarch64-buildroot-linux-gnu/sysroot/usr/bin/phpize
History:查看历史
6.执行configure
./configure --build=x86_64-redhat-linux --host=aarch64-buildroot-linux-gnu --target=aarch64-buildroot-linux-gnu --with-php-config=/usr/cneos/buildarm64/ft-yinhe-cross/host/aarch64-buildroot-linux-gnu/sysroot/usr/bin/php-config
7.编译: make
8.清理缓存 make clean
9.安装生成扩展库: make install

查看生成so库的具体内容:objdump -x +so文件路径

2.举例:
1.解压并进入:
cd /root/php-5.3.28/ext
2.骨架
./ext_skel --extname=xianwenjun
3.编辑代码和配置
cd xianwenjun
vim xianwenjun.c进入:
PHP_FUNCTION(xianwenjun_helloworld)
{
php_printf(“hello,xwj”); //函数定义
}

PHP_FE(xianwenjun_helloworld,   NULL)  //函数注册声明

3.2:修改配置
vim config.m4
3.3.1.with

with是作为动态链接库载入的
dnl PHP_ARG_WITH(testext, for testext support,
dnl Make sure that the comment is aligned:
dnl [  --with-testext             Include testext support])
修改内容为

PHP_ARG_WITH(testext, for testext support,
dnl Make sure that the comment is aligned:
[  --with-testext             Include testext support])
3.3.2.enable

表示编译到php内核中.这个配置文件创造了一个--enable-testext的配置选项,而			PHP_ARG_ENABLE的第二个选项会在配置的时候显示出来
dnl PHP_ARG_ENABLE(testext, whether to enable testext support,
dnl Make sure that the comment is aligned:
dnl [  --enable-testext           Enable testext support])

修改内容为

PHP_ARG_ENABLE(testext, whether to enable testext support,
dnl Make sure that the comment is aligned:
[  --enable-testext           Enable testext support])

4.执行configure
./configure --host=目标主机平台(如:aarch64-redhat-linux)
–build=编译平台 --with-php-config=编译配置(如:/usr/cneos/buildarm64/ft-yinhe-cross/host/aarch64-buildroot-linux-gnu/sysroot/usr/bin/php-config)

可能用到相关查找命令:如find / -name php-config查找php-config所在位置。

例子;./configure --build=x86_64-redhat-linux --host=aarch64-redhat-linux --with-php-config=/usr/cneos/buildarm64/ft-yinhe-cross/host/aarch64-buildroot-linux-gnu/sysroot/usr/bin/php-config

5.make编译,make install 安装生成扩展
make
make install
结束后生成的库在它显示信息的路劲下。

遇到的坑:
由于是交叉编译,需要将生成的库放在其他平台使用,所以执行./configure时后面参数至关重要。所以需要检查生成库是否满足要求:
objdump -x 生成库路径查看库详细信息
特别注意objdump -x显示的库文件信息中架构是什么,是不是你所想的架构

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值