Ich verwende PHP-cpp zum Erstellen einer PHP-Erweiterung.Php-cpp Aufruf zu undefinierter Funktion
main.cpp
#include <phpcpp.h>
#include <iostream>
using namespace std;
void helloWorld(Php::Parameters ¶ms)
{
string name = params[0];
cout << "Hello" << name << endl;
}
extern "C" {
/**
* Function that is called by PHP right after the PHP process
* has started, and that returns an address of an internal PHP
* strucure with all the details and features of your extension
*
* @return void* a pointer to an address that is understood by PHP
*/
PHPCPP_EXPORT void *get_module()
{
static Php::Extension extension("yourextension", "1.0");
extension.add("helloWorld", helloWorld);
return extension;
}
}
Dann lief ich make && sudo make install
$, die
make: Nothing to be done for 'all'.
cp -f yourextension.so /usr/lib/php/20151012
cp -f yourextension.ini /etc/php/7.0/cli/conf.d
die config-php prüfen
[email protected]:~/EmptyExtension$ php -i | grep -i yourextension
/etc/php/7.0/cli/conf.d/yourextension.ini
yourextension
für mich in Ordnung scheint, so dass ich versuche helloWorld()
zu verwenden
test.php
<?php
echo extension_loaded('yourextension'); // outputs 1
echo helloWorld('it works');
Aber es funktioniert nicht;)
Errormessage Uncaught Error: Call to undefined function helloWorld()
Irgendwelche Ideen? Ich bin mit Ubuntu 16.04 und php7.0.8
Vielen Dank
EDIT Wenn kompilierte PHP-CPP ich folgende Ausgabe bekommen, vielleicht gibt es etwas falsch schon?
[email protected]:~/PHP-CPP$ sudo make install
mkdir -p /usr/include/phpcpp
mkdir -p /usr/lib
cp -f phpcpp.h /usr/include
cp -f include/*.h /usr/include/phpcpp
if [ -e libphpcpp.so.2.0.0 ]; then \
cp -f libphpcpp.so.2.0.0 /usr/lib/; \
ln -f -s /usr/lib/libphpcpp.so.2.0.0 /usr/lib/libphpcpp.so.2.0; \
ln -f -s /usr/lib/libphpcpp.so.2.0.0 /usr/lib/libphpcpp.so; \
fi
if [ -e libphpcpp.a.2.0.0 ]; then cp -f libphpcpp.a.2.0.0 /usr/lib/; \
ln -f -s /usr/lib/libphpcpp.a.2.0.0 /usr/lib/libphpcpp.a; \
fi
if `which ldconfig`; then \
sudo ldconfig; \
fi
EDIT [2] Die Funktion scheint auch nicht exportiert
[email protected]:~/EmptyExtension$ sudo nm -D /usr/lib/php/20151012/yourextension.so
0000000000201060 B __bss_start
U __cxa_atexit
w __cxa_finalize
U __cxa_guard_abort
U __cxa_guard_acquire
U __cxa_guard_release
0000000000201060 D _edata
0000000000201130 B _end
0000000000000a6c T _fini
00000000000009c0 T get_module
w __gmon_start__
U __gxx_personality_v0
0000000000000810 T _init
w _ITM_deregisterTMCloneTable
w _ITM_registerTMCloneTable
w _Jv_RegisterClasses
U _Unwind_Resume
U _ZN3Php9Extension6moduleEv
U _ZN3Php9ExtensionC1EPKcS2_i
U _ZN3Php9ExtensionD1Ev