callback_for_c中的 Php::call()函数中的 function 是C++11的特性:
template <typename ...Params>
Value call(const char *name, Params&&... params)
{
// the name can be turned into a Php::Value object, which implements
// the operator () method to call it
Value function(name);
// invoke the operator ()
return function(std::forward<Params>(params)...);
}
#0 0x006c19f0 in _emalloc ()
#1 0xb6f57374 in zend_string_alloc (persistent=0, len=13) at /usr/include/php-zts/php/Zend/zend_string.h:122
#2 zend_string_init (persistent=0, len=13, str=0xb6ff0181 "some_function") at /usr/include/php-zts/php/Zend/zend_string.h:158
更多相关内容可看:http://bbs.csdn.net/topics/392309417
是不是comm.a也要在支持C++11的编译器件上编译并且将-std=c++11库链进去才可以?
我们编译b.cpp的时候(b.cpp在机器B上编译,机器B上的gcc是4.8,支持C++11,编译出来的程序也是在机器B上执行),Php::Value data = Php::call("some_function", "some_parameter"); 这一句所有相关的代码(function……等)和依赖(c++11等)没有编到函数callback_for_c里面吗?callback_for_c最终不就是一个二进制的代码块吗? 对执行它的库/环境还有要求?
...全文
56211打赏收藏
关于C库中回调C++函数的库依赖的一些问题(题目比较特殊回答前能先耐心看完题目)
这是我的程序文件b.cpp中函数 #ifdef __cplusplus extern "C" { #endif int32 callback_for_c(int32 lIdentifyCode,int16 nMsgType,void *pstMsg,int32 lMsgLen) { Php::Value relt; printf("callback c function sucess!\n"); // call a function from user space 调用用户的函数 Php::V
#ifdef __cplusplus
extern "C" {
#endif
int32 callback_for_c(int32 lIdentifyCode,int16 nMsgType,void *pstMsg,int32 lMsgLen)
{
Php::Value relt;
printf("callback c function sucess!\n");
// call a function from user space 调用用户的函数
Php::Value data = Php::call("some_function", "some_parameter");
printf("%s\n", "i arrival here!");
return int32_t(relt);
}
#ifdef __cplusplus
}
#endif
改成:
#ifdef __cplusplus
extern "C"
#endif
int32 callback_for_c(int32 lIdentifyCode,int16 nMsgType,void *pstMsg,int32 lMsgLen)
{
Php::Value relt;
printf("callback c function sucess!\n");
// call a function from user space 调用用户的函数
Php::Value data = Php::call("some_function", "some_parameter");
printf("%s\n", "i arrival here!");
return int32_t(relt);
}