var_dump(dl(“ehphp.dylib”); 布尔(真) php>var_转储(函数_存在(“bar”)); 布尔(真) php>var_转储(class_存在(“示例”); 布尔(假) php>,php,c++,swig,Php,C++,Swig" /> var_dump(dl(“ehphp.dylib”); 布尔(真) php>var_转储(函数_存在(“bar”)); 布尔(真) php>var_转储(class_存在(“示例”); 布尔(假) php>,php,c++,swig,Php,C++,Swig" />

集成C++;使用SWIG将类转换为PHP 我使用SWIG将C++类集成到PHP中,但是由于某种原因,即使在函数中出现了正确的函数,类也不会在PHP中正确显示。这是MacOSX10.5.8上的SWIG2.0.4和PHP5.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 > $cat示例.i %{ #包括 #包括“example.h” int示例::foo(void){ printf(“这是foo\n”); 返回0; } %} %模块示例 课例{ 公众: int foo(无效); }; $cat示例.h 课例{ 公众: int foo(无效); }; $make ehphp /opt/local/bin/swig-c++-php5-example.i g++`php配置--包括`-fPIC-c example\u wrap.cpp-o example\u wrap.o (U,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,U,zend,get参数,数组,ex,-U、 函数-U,转换为字符串-U,哈希-U,添加或更新-U,全局执行器-U,用于-U init,-U,zval\U为-U true,-U,对象-U init,-U,php\U strotlower ehu,estru-dup,-U init object-U,php-dup,-php-du init-du-du,php-du-du-du-du-du-du-du-du-du-du-du-du-du-du-du-du-du-du-du-du-du-du-du-du类 sudo cp ehphp.dylib/opt/local/lib/php/extensions/no-debug-non-zts-20090626/ehphp.dylib $php-a 交互式shell php>var_dump(dl(“ehphp.dylib”); 布尔(真) php>var_转储(函数_存在(“bar”)); 布尔(真) php>var_转储(class_存在(“示例”); 布尔(假) php>

集成C++;使用SWIG将类转换为PHP 我使用SWIG将C++类集成到PHP中,但是由于某种原因,即使在函数中出现了正确的函数,类也不会在PHP中正确显示。这是MacOSX10.5.8上的SWIG2.0.4和PHP5.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 > $cat示例.i %{ #包括 #包括“example.h” int示例::foo(void){ printf(“这是foo\n”); 返回0; } %} %模块示例 课例{ 公众: int foo(无效); }; $cat示例.h 课例{ 公众: int foo(无效); }; $make ehphp /opt/local/bin/swig-c++-php5-example.i g++`php配置--包括`-fPIC-c example\u wrap.cpp-o example\u wrap.o (U,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,U,zend,get参数,数组,ex,-U、 函数-U,转换为字符串-U,哈希-U,添加或更新-U,全局执行器-U,用于-U init,-U,zval\U为-U true,-U,对象-U init,-U,php\U strotlower ehu,estru-dup,-U init object-U,php-dup,-php-du init-du-du,php-du-du-du-du-du-du-du-du-du-du-du-du-du-du-du-du-du-du-du-du-du-du-du-du类 sudo cp ehphp.dylib/opt/local/lib/php/extensions/no-debug-non-zts-20090626/ehphp.dylib $php-a 交互式shell php>var_dump(dl(“ehphp.dylib”); 布尔(真) php>var_转储(函数_存在(“bar”)); 布尔(真) php>var_转储(class_存在(“示例”); 布尔(假) php>,php,c++,swig,Php,C++,Swig,我想你应该 require "Example.php"; 以加载代理类。(那个php文件是由SWIG生成的。)我相信你应该这样做 require "Example.php"; 以加载代理类。(这个php文件是由SWIG生成的。)这个php文件仅仅包装了我在php-a中单独进行的“dl”调用,而不仅仅是我在这里所做的。在example.i文件上调用swig,example.php文件包含的不仅仅是DLL加载。特别是,它有一个类示例;我没有意识到SWIG将此代码放在了.php文件中(它没有为函数

我想你应该

require "Example.php";

以加载代理类。(那个
php
文件是由SWIG生成的。)

我相信你应该这样做

require "Example.php";

以加载代理类。(这个
php
文件是由SWIG生成的。)

这个php文件仅仅包装了我在php-a中单独进行的“dl”调用,而不仅仅是我在这里所做的。在example.i文件上调用swig,example.php文件包含的不仅仅是DLL加载。特别是,它有一个
类示例
;我没有意识到SWIG将此代码放在了.php文件中(它没有为函数放任何类似的实质性内容)。谢谢你的帮助!这个PHP文件仅仅包装了我在PHP-a中单独进行的“dl”调用,而不仅仅是我在这里所做的。在example.i文件上调用swig,example.php文件包含的不仅仅是DLL加载。特别是,它有一个
类示例
;我没有意识到SWIG将此代码放在了.php文件中(它没有为函数放任何类似的实质性内容)。谢谢你的帮助+1以获取完整但最少的示例。(您可以使用
%inline%{%}
将其简化为一个.i文件)+1作为一个完整但最小的示例。(您可以使用
%inline%{%}
将其简化为一个.i文件)