用php的c扩展编程调用 c程序的动态链接库
一. 首先做一个简单的so文件:
/**
* hello.c
* To compile, use following commands:
* gcc -O -c -fPIC -o hello.o hello.c
* gcc -shared -o libhello.so hello.o
*/
int hello_add(int a, int b)
{
return a + b;
}
然后将它编译成.so文件并放到系统中:
$ gcc -O -c -fPIC -o hello.o hello.c
$ gcc -shared -o libhello.so hello.o
$ su
# echo /usr/local/lib > /etc/ld.so.conf.d/local.conf
# cp libhello.so /usr/local/lib
# /sbin/ldconfig
二. 写段小程序来验证其正确性:
/**
* hellotest.c
* To compile, use following commands:
* gcc -o hellotest -lhello hellotest.c
*/
#include <stdio.h>
int main()
{
int a = 3, b = 4;
printf("%d + %d = %d\n", a, b, hello_add(a,b));
return 0;
}
编译并执行:
$ gcc -o hellotest -lhello hellotest.c
$ ./hellotest
3 + 4 = 7
三.
然后通过下面的命令建立一个名为 hello 的模块。
$ ./ext_skel --extname=hello
执行该命令之后它会提示你应当用什么命令来编译模块,可惜那是将模块集成到php内部的编译方法。如果要编译成可动态加载的 php_hello.so,方法要更为简单。
$ cd hello
首先编辑 config.m4 文件,去掉第16行和第18行
相关文档:
Google Android开发博客今天宣布,即日起开放针对Android平台的原生软件开发SDK下载。由于在SDK前面又加上了原生二字,即Native Development Kit,因此又被Google称为NDK。在此之前,Android平台的第三方应用程序均是依靠基于Java的Dalvik特制虚拟机进行开发的。原生 SDK的公布可以让开发者更加直接的接触Android系统资源, ......
Google Android开发博客今天宣布,即日起开放针对Android平台的原生软件开发SDK下载。由于在SDK前面又加上了原生二字,即Native Development Kit,因此又被Google称为NDK。在此之前,Android平台的第三方应用程序均是依靠基于Java的Dalvik特制虚拟机进行开发的。原生 SDK的公布可以让开发者更加直接的接触Android系统资源, ......
6000甚至10000,都可以,但大于6000,就开始滚屏了。。
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
int main(){
int i,j,*f,tmp,c=0;
long int n,bits;
const double PI=2*asin(1.0),E=exp(1.0);
scanf("%ld",&n);
bits=(long)ceil(n*(log10(n)-log ......
找错题
试题1:
void test1()
{
char string[10];
char* str1 = "0123456789";
strcpy( string, str1 );
}
试题2:
void test2()
{
char string[10], str1[10];
int i;
for(i=0; i<10; i++)
{
str1[i] = 'a';
}
strcpy( string, str1 );
}
试题3:
void test3( ......