gpt4 book ai didi

php - 编译 php-cpp main.cpp 文件时忽略类型属性或对 phpExtension 错误的 undefined reference

转载 作者:行者123 更新时间:2023-11-30 05:27:39 26 4
gpt4 key购买 nike

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

最佳答案

根据official documentation您必须将您的二进制文件与 -lphpcpp 链接起来。示例 Makefile 包含以下几行:

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

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

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

关于php - 编译 php-cpp main.cpp 文件时忽略类型属性或对 phpExtension 错误的 undefined reference ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37155054/

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