用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行
相关文档:
1.开发工具下载
TUBER C http://www.duote.com/soft/392.html
Turbo C 2.0 汉化版 http://www.programfan.com/showdown.asp?id=306
C-Free 4.0 http:/ ......
Google Android开发博客今天宣布,即日起开放针对Android平台的原生软件开发SDK下载。由于在SDK前面又加上了原生二字,即Native Development Kit,因此又被Google称为NDK。在此之前,Android平台的第三方应用程序均是依靠基于Java的Dalvik特制虚拟机进行开发的。原生 SDK的公布可以让开发者更加直接的接触Android系统资源, ......
#include<stdlib.h>
#include<iostream>
#include<string.h>
using namespace std;
int main(void)
{
FILE *fp, *fp2;
char buf[1024*300];
fp = fopen("in.txt", "rb");
fp2 = fopen("out.txt", "wb+");
fseek(fp, 0, SEEK_END);
int iLen ......
函数名: stpcpy
功 能: 拷贝一个字符串到另一个
用 法: char *stpcpy(char *destin, char *source);
程序例:
#include <stdio.h>
#include <string.h>
int main(void)
{
char string[10];
char *str1 = "abcdefghi";
stpcpy(string, str1);
& ......
找错题
试题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( ......