一、制作第三方动态库 file hellotest.c # include stdio.h# include stdlib.hint hello_add(int a, int b){return a+b;} filehellotest.h int hello_add(int a, int b); 编译生成动态库文件 # gcc-fPIC hellotest.c -c # gcc-fPIC -shared -o libhellotest.
一、制作第三方动态库
file hellotest.c |
# include <stdio.h> # include <stdlib.h> int hello_add(int a, int b) { return a+b; }</stdlib.h></stdio.h> |
file hellotest.h
int hello_add(int a, int b);
编译生成动态库文件
# gcc-fPIC hellotest.c -c
# gcc-fPIC -shared -o libhellotest.so hellotest.o
将生成的动态库文件拷贝到/lib目录下
二、制作PHP扩展库
- 编译安装php5.5
- 自动构建扩展库目录
# ./ext_skel --extname=
会自动生成config.m4, php_test.h, test.c等几个文件。
- 修改文件
1)修改config.m4文件,去掉dnl,
PHP_ARG_ENABLE(test, whether to enable test support,
make sure that the comment is aligned:
[ --enable-test Enable testsupport])
if test "$PHP_TEST" != "no"; then
- 修改php_test.h文件
PHP_FUNCTION(confirm_test_compiled);
改为:PHP_FUNCTION(php_hello_add);
- 修改test.c文件
zend_function_entry test_functions[] = {
PHP_FE(confirm_test_compiled, NULL)
改为:PHP_FE(php_hello_add, NULL)
{NULL, NULL, NULL}
};
PHP_FUNCTION(php_hello_add)
{
long int a, b;
long int result;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC,"ll", &a, &b)
== FAILURE)
{
return;
}
result = hello_add(a, b);
RETURN_LONG(result);
}
......
}
其中,php_hello_add为PHP脚本可直接调用的扩展函数。
- 扩展模块编译
# cd ext/test
# phpize
# ./configure --with-php-config=/usr/local/bin/php-config--enable-test
# make LDFLAGS=-lhellotest
# make install
5.修改php.ini文件
[PHP] extension=ext_name.so
三、编译安装Mongoose
四、测试
编写php测试代码
$result = php_hello_add(9, 5);
print("php_hello_add(9, 5)=$result
");
?>

핫 AI 도구

Undresser.AI Undress
사실적인 누드 사진을 만들기 위한 AI 기반 앱

AI Clothes Remover
사진에서 옷을 제거하는 온라인 AI 도구입니다.

Undress AI Tool
무료로 이미지를 벗다

Clothoff.io
AI 옷 제거제

AI Hentai Generator
AI Hentai를 무료로 생성하십시오.

인기 기사

뜨거운 도구

VSCode Windows 64비트 다운로드
Microsoft에서 출시한 강력한 무료 IDE 편집기

SublimeText3 영어 버전
권장 사항: Win 버전, 코드 프롬프트 지원!

스튜디오 13.0.1 보내기
강력한 PHP 통합 개발 환경

mPDF
mPDF는 UTF-8로 인코딩된 HTML에서 PDF 파일을 생성할 수 있는 PHP 라이브러리입니다. 원저자인 Ian Back은 자신의 웹 사이트에서 "즉시" PDF 파일을 출력하고 다양한 언어를 처리하기 위해 mPDF를 작성했습니다. HTML2FPDF와 같은 원본 스크립트보다 유니코드 글꼴을 사용할 때 속도가 느리고 더 큰 파일을 생성하지만 CSS 스타일 등을 지원하고 많은 개선 사항이 있습니다. RTL(아랍어, 히브리어), CJK(중국어, 일본어, 한국어)를 포함한 거의 모든 언어를 지원합니다. 중첩된 블록 수준 요소(예: P, DIV)를 지원합니다.

SublimeText3 Mac 버전
신 수준의 코드 편집 소프트웨어(SublimeText3)
