编译php cpp main.cpp文件时忽略或未定义对phpExtension错误的类型属性引用

编译php cpp main.cpp文件时忽略或未定义对phpExtension错误的类型属性引用,php,c++,g++,php-cpp,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 alre

我正在使用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是我的扩展名。

根据,您必须将二进制文件链接到
-lphpcpp
。示例
Makefile
包含以下行:

COMPILER_FLAGS      =   -Wall -c -O2 -std=c++11 -fpic -o
LINKER_FLAGS        =   -shared
LINKER_DEPENDENCIES =   -lphpcpp
因此,为了正确构建扩展,编译器/链接器需要比您在命令中传递的信息更多的信息


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

我以前负责编辑该文件,我的链接器依赖项是:/home/WorkSpace/PHP-CPP/libphpcpp.so.1.5。2@Amir,我清楚地看到您没有注意到链接标志,至少:
g++-std=gnu++11 main.cpp
。您的帖子中的输出包含关于对象文件的错误,因此是关于链接阶段的。另外,请尝试清理和制作谢谢您的时间,但我想我没有得到您想说的部分内容。这是您在扩展目录的make文件中提到的三行代码:
COMPILER\u FLAGS=-Wall-c-O2-std=gnu++11-fPIC-o LINKER\u FLAGS=-shared LINKER\u DEPENDENCIES=/usr/lib/libphpcpp。那么
我应该在这些行中编辑哪一部分?我编辑了链接器依赖项。还有什么要做的吗?还有,每次我想用g++命令编译时,我都会将-std=c++11或-std=gnu++11添加到命令行。@阿米尔,你不应该直接调用
g++
!改用makefile。如果
main.cpp
应该是项目的一部分,那么相应地调整
Makefile