2016-08-17 7 views
1

私はphp拡張を作成するためにphp-cppを使用しています。 main.cppにPhp-cpp未定義関数を呼び出す

#include <phpcpp.h> 
#include <iostream> 

using namespace std; 

void helloWorld(Php::Parameters &params) 
{ 
    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; 
    } 
} 

は、その後、私は

[email protected]:~/EmptyExtension$ php -i | grep -i yourextension 
/etc/php/7.0/cli/conf.d/yourextension.ini 
yourextension 

が私のために罰金だPHPの設定を確認する

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 

を出力する$ make && sudo make installを走ったので、私はhelloWorld()を使用しようと

test.phpを

<?php 

echo extension_loaded('yourextension'); // outputs 1 
echo helloWorld('it works'); 

しかし、それは動作しません。)

にErrorMessage Uncaught Error: Call to undefined function helloWorld()

任意のアイデア? 私はUbuntuのに16.04とphp7.0.8

どうもありがとう

EDIT コンパイルのphp-CPP私は出力を次のようになっています、多分すでに何かが間違っているを使用していますか?

[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] を機能が

[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 

答えて

0

これに対する解決策は、彼らが$ make && sudo make installによって上書きされ得ることはありませんので、コンパイルされたファイルを削除するために、あるをエクスポートするにもないようです。

ので$ rm -f main.o yourextension.so && make && sudo make installは、あなたがそれを正しく実行する必要があり、ここで

0

まずトリックをしました。それをコンパイルするには、以下のコマンドを実行する必要があります。

  1. sudoを作る
  2. をmake installをあなたがこれらの4つの手順に従わなければなりません-B
  3. PHPのtest.phpを

を作ります。

関連する問題