Simple Hello World PHP extension cannot be done
I am trying to run a simple Hello World PHP extension, but after building and installing the extension and when I want to run a test script, I have the following problem:
P Warning: PHP Startup: Unable to load dynamic library '/usr/lib/php5/20121212/skeleton.so' - /usr/lib/php5/20121212/skeleton.so: undefined symbol: _ZN3Php9ExtensionD1Ev in Unknown on line 0
/etc/php5/cli/conf.d/skeleton.ini
My main.cpp
file:
#include <phpcpp.h>
#include <iostream>
void helloWorld (Php::Parameters ¶ms)
{
std::string name=params[0];
std::cout<<"Hello "<<name<<"!"<<std::endl;
}
extern "C" {
PHPCPP_EXPORT void *get_module()
{
static Php::Extension extension("skeleton", "1.0");
extension.add("helloWorld", helloWorld);
return extension;
}
}
And here is my test script:
<?php
echo helloWorld('Ben');
I was inspired by this tutorial: http://www.sitepoint.com/getting-started-php-extension-development-via-php-cpp/
Could you help me with this? Thanks in advance for your help.
source to share
I was getting the same error until I saw this ticket on PHP-CPP repos: https://github.com/CopernicaMarketingSoftware/PHP-CPP/issues/180
It turns out my problem was that I was following another advice to replace the content of the /zend/
dir file (in the PHP-CPP lib) with the content of the PHP source code (which I got from php.net).
Once I returned the content /zend/
to be the same as PHP-CPP, the problem went away.
source to share