gpt4 book ai didi

php - 使用 SWIG 将 C++ 类集成到 PHP 中

转载 作者:太空宇宙 更新时间:2023-11-04 12:13:39 25 4
gpt4 key购买 nike

我正在使用 SWIG 将 C++ 类集成到 PHP 中,但由于某种原因,该类在 PHP 中显示不正确,即使函数确实显示正确。这是 Mac OS X 10.5.8 上的 SWIG 2.0.4 和 PHP 5.3.6。以下是用于构建库的代码和命令:

$ cat example.i
%{
#include <stdio.h>
#include "example.h"
int Example::foo(void) {
printf("This is foo\n");
return 0;
}
%}
%module example

class Example {
public:
int foo(void);
};
$ cat example.h
class Example {
public:
int foo(void);
};
$ make ehphp
/opt/local/bin/swig -c++ -php5 example.i
g++ `php-config --includes` -fPIC -c example_wrap.cpp -o example_wrap.o
g++ -dynamiclib -Wl,-flat_namespace,-U,_zend_register_resource,-U,_zend_rsrc_list_get_rsrc_type,-U,_zend_wrong_param_count,-U,_compiler_globals,-U,_zend_hash_find,-U,_gc_remove_zval_from_buffer,-U,_zend_register_long_constant,-U,_zend_get_constant,-U,__efree,-U,__emalloc,-U,_zend_error,-U,__zend_list_find,-U,_main,-U,__zend_get_parameters_array_ex,-U,_zend_register_list_destructors_ex,-U,__zval_copy_ctor_func,-U,__convert_to_string,-U,__zend_hash_add_or_update,-U,_executor_globals,-U,_zval_used_for_init,-U,_zval_is_true,-U,__object_init,-U,_php_strtolower,-U,__estrndup,-U,__object_init_ex,-U,_zend_lookup_class -o ehphp.dylib example_wrap.o
sudo cp ehphp.dylib /opt/local/lib/php/extensions/no-debug-non-zts-20090626/ehphp.dylib
$ php -a
Interactive shell

php > var_dump(dl("ehphp.dylib"));
bool(true)
php > var_dump(function_exists("bar"));
bool(true)
php > var_dump(class_exists("Example"));
bool(false)
php >

最佳答案

我相信你应该

require "Example.php";

加载代理类。 (该 php 文件由 SWIG 生成。)

关于php - 使用 SWIG 将 C++ 类集成到 PHP 中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8688993/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com