I'm using php-cpp to create an extension for my php codes and when I try to compile just the simple structure of main.cpp file, I get some weird errors.
this is the compile errors:
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
what is /tmp/cctI8mp.o ??? or the other ones?and the mentioned cctI8mp.o changes to another name each time I compile
and this is the code that I try to compile:
#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 is the name of my extension.
According to the official documentation you have to link your binary with
-lphpcpp. The sampleMakefilecontains the following lines:So to build the extension properly, the compiler/linker needs more information than you passed in your command.
Consider copying and modifying the sample
Makefile. Note, in order to build the extension usingMakefileyou have to runmakecommand(which will look for the makefiles in the current directory by default).