Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Simple Hello World PHP extension could not be executed

I am trying to run simple Hello World PHP extension, but after make & install extension and when I want to run test script I am experiencing following issue:

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 &params)
{
    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 have been inspired by this tutorial: http://www.sitepoint.com/getting-started-php-extension-development-via-php-cpp/

Could you help me with this one? Thanks in advance for your help.

like image 217
Tom11 Avatar asked May 20 '26 07:05

Tom11


1 Answers

I'm not sure if this is the problem, but you should use:

Php::out << "Hello " << name << "!" << std::endl;

instead of

std::cout << "Hello " << name << "!" << std::endl;

std::cout produces some errors in my extensions.

Vinicius

like image 71
Vinicius Pontes Avatar answered May 22 '26 21:05

Vinicius Pontes