ubuntuusers.de

php erweiterng schreiben...

Status: Ungelöst | Ubuntu-Version: Ubuntu 16.10 (Yakkety Yak)
Antworten |

tomovic

(Themenstarter)
Avatar von tomovic

Anmeldungsdatum:
25. August 2013

Beiträge: 231

  • -with-myfunctions=shared,/home/tomovic/Downloads/php-5.5.38/ext/myfunctions

Das gleiche in blau Er kennt kein --with-myfunctions

Aber der Ordner in ext heißer myfunctions

seahawk1986

Anmeldungsdatum:
27. Oktober 2006

Beiträge: 11241

Wohnort: München

Verrät dir dein Buch nicht mehr dazu, wie man das mit dem Build-System verheiraten kann? Ich habe das noch nie selbst gemacht, aber http://abhinavsingh.com/php-extensions-how-and-why/ deutet darauf hin, dass man da dem Build-System noch mitteilen muss, das es die Extension gibt.

tomovic

(Themenstarter)
Avatar von tomovic

Anmeldungsdatum:
25. August 2013

Beiträge: 231

ok, nochmal intensiv gegoolet ☺

http://www.hackingwithphp.com/20/3/0/first-step

Im Allgemeinen muss ich nach...

./ext_skel --extame=hello

..in der config.m4 Datei Zwei Teile einkommentieren:

PHP_ARG_ENABLE(hello, whether to enable hello support,
dnl Make sure that the comment is aligned:
[  --enable-hello           Enable hello support])

Dann gibt man in Die Console ein: ./buildconf --force

mein Ergebnis:

root@DELL:~/Downloads/php-5.5.38# ./buildconf --force
Forcing buildconf
Removing configure caches
rebuilding configure
/usr/bin/m4:ext/sample/config.m4:2: ERROR: end of file in string
autom4te: /usr/bin/m4 failed with exit status: 1
root@DELL:~/Downloads/php-5.5.38# 

ahhhhhhhhhhhhhhhh, keiner auf der Welt hat das gleiche Problem wie ich, laut google ☹

Bearbeitet von sebix:

Forensyntax korrigiert.

tomovic

(Themenstarter)
Avatar von tomovic

Anmeldungsdatum:
25. August 2013

Beiträge: 231

... Nachtrag: Der Link von Dir und das Ergebnis:

root@DELL:~/Downloads/php-5.5.38/ext/sample# phpize
Configuring for:
PHP Api Version:         20121113
Zend Module Api No:      20121212
Zend Extension Api No:   220121212
/usr/bin/m4:config.m4:2: ERROR: end of file in string
autom4te: /usr/bin/m4 failed with exit status: 1
root@DELL:~/Downloads/php-5.5.38/ext/sample# 

seahawk1986

Anmeldungsdatum:
27. Oktober 2006

Beiträge: 11241

Wohnort: München

Wie sieht denn die angemeckerte config.m4 Datei aus?

tomovic

(Themenstarter)
Avatar von tomovic

Anmeldungsdatum:
25. August 2013

Beiträge: 231

dnl $Id$
dnl config.m4 for extension hello

dnl Comments in this file start with the string 'dnl'.
dnl Remove where necessary. This file will not work
dnl without editing.

dnl If your extension references something external, use with:

PHP_ARG_WITH(hello, whether to enable hello support,
dnl Make sure that the comment is aligned:
[  --with-hello           Enable hello support])


dnl Otherwise use enable:


if test "$PHP_HELLO" != "no"; then
  dnl Write more examples of tests here...

  dnl # --with-hello -> check with-path
  dnl SEARCH_PATH="/usr/local /usr"     # you might want to change this
  dnl SEARCH_FOR="/include/hello.h"  # you most likely want to change this
  dnl if test -r $PHP_HELLO/$SEARCH_FOR; then # path given as parameter
  dnl   HELLO_DIR=$PHP_HELLO
  dnl else # search default path list
  dnl   AC_MSG_CHECKING([for hello files in default path])
  dnl   for i in $SEARCH_PATH ; do
  dnl     if test -r $i/$SEARCH_FOR; then
  dnl       HELLO_DIR=$i
  dnl       AC_MSG_RESULT(found in $i)
  dnl     fi
  dnl   done
  dnl fi
  dnl
  dnl if test -z "$HELLO_DIR"; then
  dnl   AC_MSG_RESULT([not found])
  dnl   AC_MSG_ERROR([Please reinstall the hello distribution])
  dnl fi

  dnl # --with-hello -> add include path
  dnl PHP_ADD_INCLUDE($HELLO_DIR/include)

  dnl # --with-hello -> check for lib and symbol presence
  dnl LIBNAME=hello # you may want to change this
  dnl LIBSYMBOL=hello # you most likely want to change this 

  dnl PHP_CHECK_LIBRARY($LIBNAME,$LIBSYMBOL,
  dnl [
  dnl   PHP_ADD_LIBRARY_WITH_PATH($LIBNAME, $HELLO_DIR/$PHP_LIBDIR, HELLO_SHARED_LIBADD)
  dnl   AC_DEFINE(HAVE_HELLOLIB,1,[ ])
  dnl ],[
  dnl   AC_MSG_ERROR([wrong hello lib version or lib not found])
  dnl ],[
  dnl   -L$HELLO_DIR/$PHP_LIBDIR -lm
  dnl ])
  dnl
  dnl PHP_SUBST(HELLO_SHARED_LIBADD)

  PHP_NEW_EXTENSION(hello, hello.c, $ext_shared)
fi

seahawk1986

Anmeldungsdatum:
27. Oktober 2006

Beiträge: 11241

Wohnort: München

Versuch doch mal in der ./buildconf (oder den davon aufgerufenen Skripten) den Aufruf von /usr/bin/m4 um das Argument -d zu erweitern, vielleicht sieht man dann besser, woran es hängt.

tomovic

(Themenstarter)
Avatar von tomovic

Anmeldungsdatum:
25. August 2013

Beiträge: 231

thx, aber das Problem lag an den rechten der config Datei.

Man sollte, wenn jemand ein Tut list, alles Schritt für Schritt ausführen. Sprich nichts überspringen, kein Handstand und kein Überschlag. Wie ich ☺

Ich habe mit ext_skel ein Projekt myfunctions erstellt. Ich habe herumgespielt und nun will ich ihn los werden. Obwohl ich den Ordner gelöscht habe, wird er mit ./configure wieder erstellt und bei make kommt eine Fehlermeldung myfunction ist kann nicht geladen werden blablalb Fehler. Wie kann ich ein Projekt löschen?

seahawk1986

Anmeldungsdatum:
27. Oktober 2006

Beiträge: 11241

Wohnort: München

Reicht es nicht make clean auszuführen, um alle temporären bzw. dynamisch erstellten Dateien loszuwerden?

tomovic

(Themenstarter)
Avatar von tomovic

Anmeldungsdatum:
25. August 2013

Beiträge: 231

... hat was mit config zu tun.

ok, ich habe jetzt einfach Ordner funktction gelöscht und das Projekt mit ./ext_skel erstellt.

Jetzt bin ich so vorgegangen:

./buildconf --force
 

./configure --enable-debug --enable-maintainer-zts --with-apxs2 --disable-cgi --enable-cli --without-pear --disable-xml --without-mysql --enable-hello

Ausgabe Schnipp...
creating main/internal_functions_cli.c
+--------------------------------------------------------------------+
|                        *** WARNING ***                             |
|                                                                    |
| You have built PHP for Apache's current non-threaded MPM.          |
| If you change Apache to use a threaded MPM you must reconfigure    |
| PHP with --enable-maintainer-zts                                   |
+--------------------------------------------------------------------+
| License:                                                           |
| This software is subject to the PHP License, available in this     |
| distribution in the file LICENSE.  By continuing this installation |
| process, you are bound by the terms of this license agreement.     |
| If you do not agree with the terms of this license, you must abort |
| the installation process at this point.                            |
+--------------------------------------------------------------------+

Thank you for using PHP.

config.status: creating php5.spec
config.status: creating main/build-defs.h
config.status: creating scripts/phpize
config.status: creating scripts/man1/phpize.1
config.status: creating scripts/php-config
config.status: creating scripts/man1/php-config.1
config.status: creating sapi/cli/php.1
config.status: creating ext/phar/phar.1
config.status: creating ext/phar/phar.phar.1
config.status: creating main/php_config.h
config.status: main/php_config.h is unchanged
config.status: executing default commands
root@DELL:~/Downloads/php-5.5.38# 
...schnipp

make Enter
make install Enter

Wenn ich den mit Firefox 127.0.0.1/info.php aufrufe sehe ich dass hello eingebunden ist.

root@DELL:~/Downloads/php-5.5.38# php -f ext/hello/hello.php
Functions available in the test extension:
confirm_hello_compiled

Speicherzugriffsfehler (Speicherabzug geschrieben)
root@DELL:~/Downloads/php-5.5.38# 

tomovic

(Themenstarter)
Avatar von tomovic

Anmeldungsdatum:
25. August 2013

Beiträge: 231

ich habe mehrmals das Verzeichnis hello gelöscht und neu erstellt mit ext_skel, es kommt der gleiche Fehler mit Speicherzugriff. Also entschied ich mich für hellohello mit Erfolg. Meine Schritte:

./ext_skel --extame=hellohello

In der config.m4 Datei die 2 Zeilen aktiviert.

in der hellohello.c folgendes hinzugefügt

PHP_FE(hello_print, NULL)

...sowie:

PHP_FUNCTION(hello_print)
{
   char *str = NULL;
    int str_len;

    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &str, &str_len) == FAILURE) {
        return;
    }

    php_printf("%s", str);

und der in }

in der header Datei folgendes hinzugefügt

PHP_FUNCTION(hello_print);

mit....

<?php
    hellohello_print(Hellohello);
?>

... bekomme ich mit php tester.php: Hellohello

soweit so gut.

OK, nächster Abschnitt, der Inhalt von PHP_FUNCTION(hello_print) ersetzt ich mit:

 int str_len;
    char *str = NULL;
    int repeat;
    int i;

    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sl", &str, &str_len, repeat) == FAILURE) {
        return;
    }

    for (i = 0; i < repeat; ++i) {
        php_printf("%s", str);
    }

... und die tester.php sieht jetzt so aus:

<?php
    hellohello_print("11",1);
?>

mit php tester.php bekomme ich:

root@DELL:~/Schreibtisch# php tester.php 
Speicherzugriffsfehler (Speicherabzug geschrieben)
root@DELL:~/Schreibtisch# 

Marc_BlackJack_Rintsch Team-Icon

Ehemalige
Avatar von Marc_BlackJack_Rintsch

Anmeldungsdatum:
16. Juni 2006

Beiträge: 4666

Wohnort: Berlin

@tomovic: Ich bin mir ziemlich sicher das zend_parse_parameters() die Adresse von repeat haben möchte, und nicht den uninitialisierten Wert dieser Variable. Da sollte eigentlich auch der C-Compiler eine Warnung ausspucken.

tomovic

(Themenstarter)
Avatar von tomovic

Anmeldungsdatum:
25. August 2013

Beiträge: 231

hallo Marc_BlackJack_Rintsch, Mega THX,

Marc_BlackJack_Rintsch <<←–– Respekt

Es lag wirklich an dem –>>> &

Antworten |