Linking a PHP extension written in C

Edit: review my question

When creating an external PHP module in C, how do I link common objects?

+3
source share
1 answer

If your C extension code uses a shared library, you need to declare this in a file config.m4.

I highly recommend using a ext_skelscript that is included in the PHP source to create the config.m4 skeleton:

./ext_skel --extname=myextension

, --with-myextension ( --enable-myextension). config.m4 .

- :

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

  PHP_CHECK_LIBRARY($LIBNAME,$LIBSYMBOL,
  [
    PHP_ADD_LIBRARY_WITH_PATH($LIBNAME, $MYEXTENSION_DIR/lib, MYEXTENSION_SHARED_LIBADD)
    AC_DEFINE(HAVE_MYEXTENSIONLIB,1,[ ])
  ],[
    AC_MSG_ERROR([wrong $LIBNAME lib version or lib not found])
  ],[
    -L$MYEXTENSION_DIR/lib -ldl
  ])

, , :

phpize
./configure --with-myextension
make

, ( ln -s) , .

, php -m .

, - PHP config.m4 - Sara Golemon PHP, PHP George Schlossnagle.

PHP- Sara Goleman , .

+11

Source: https://habr.com/ru/post/1719076/


All Articles