在编译php-cpp main.cpp文件时,键入属性忽略或未定义对phpExtension错误的引用

时间:2016-05-11 06:48:49

标签: php c++ g++ php-cpp

我使用php-cpp为我的php代码创建扩展,当我尝试编译main.cpp文件的简单结构时,我得到了一些奇怪的错误。

这是编译错误:

g++ -std=gnu++11 main.cpp
In file included from lib/phpcpp/phpcpp.h:39:0,
             from main.cpp:122:
lib/phpcpp/type.h:32:1: warning: type attributes ignored after type is already defined [-Wattributes]
 };
 ^
In file included from lib/phpcpp/phpcpp.h:60:0,
                 from main.cpp:122:
lib/phpcpp/classtype.h:31:1: warning: type attributes ignored after type is already defined [-Wattributes]
 };
 ^
/tmp/cc0tI8mp.o: In function `get_module':
main.cpp:(.text+0x4c): undefined reference to `Php::Extension::Extension(char const*, char const*, int)'
main.cpp:(.text+0x65): undefined reference to `Php::Extension::~Extension()'
/tmp/cc0tI8mp.o: In function `Php::Extension::operator void*()':
main.cpp:(.text._ZN3Php9ExtensioncvPvEv[_ZN3Php9ExtensioncvPvEv]+0x14): undefined reference to `Php::Extension::module()'
collect2: error: ld returned 1 exit status  

什么是/tmp/cctI8mp.o ???或者其他的?并且每次编译时提到的cctI8mp.o都会更改为另一个名称

这是我尝试编译的代码:

#include "lib/phpcpp/phpcpp.h"
/**
 *  tell the compiler that the get_module is a pure C function
 */
extern "C" {
    int main(){}
 PHPCPP_EXPORT void *get_module() 
    {
        static Php::Extension bias("bias_framework_free", "0.9.3.20");
        return bias;
    }
}  

bias是我的扩展名。

1 个答案:

答案 0 :(得分:1)

根据official documentation,您必须将二进制文件与-lphpcpp相关联。示例Makefile包含以下行:

COMPILER_FLAGS      =   -Wall -c -O2 -std=c++11 -fpic -o
LINKER_FLAGS        =   -shared
LINKER_DEPENDENCIES =   -lphpcpp

因此,为了正确构建扩展,编译器/链接器需要的信息比在命令中传递的信息要多。

考虑复制和修改样本Makefile。注意,为了使用Makefile构建扩展,您必须运行make命令(默认情况下将查找当前目录中的makefile)。