8

In the past i did create a shared library that now I would like to use it inside a php extension. Is it possible to do that? As I've seen in the config.m4 file PHP_NEW_EXTENSION() asks for the .cc . The problem is that i don't want to expose my code. I just want to use the header and the shared library i've creaded in c under ubuntu.For the php extention i did create a : config.m4, php_c.h and php_c.cc.

Please help!. THX APPRECIATE I did put in the config file this:

libs=mylib.so; 
PHP_ADD_LIBRARY_WITH_PATH(libs, $EXTERNAL_LIB_DIR, ?? what to add here);

I obtain the following:

PHP Warning:  PHP Startup: Invalid library (maybe not a PHP library) '/home/foder/mylib.so'in Unknown on line 0

php: symbol lookup error:

/usr/php5/20090626+lfs/vehicles.so: undefined symbol: _ZN3CarC1Ei (where vehicles.so) is a php so created with: phpize, ./configure --enable-vehicle make..
hakre
  • 193,403
  • 52
  • 435
  • 836
sunset
  • 1,359
  • 5
  • 22
  • 35
  • 1
    You can't just take some random .so and turn it into a PHP extension with a couple lines of config. There's a fair amount of work involved: http://devzone.zend.com/article/1021 – Marc B Sep 02 '11 at 14:34

1 Answers1

16
PHP Warning:  PHP Startup: Invalid library (maybe not a PHP library) '/home/foder/mylib.so'in Unknown on line 0

This message means there's no "get_module" function in the ".so".
Make sure the PHP extension source contains the lines:

#ifdef HAVE_CONFIG_H
#include "config.h"
#endif

and

#ifdef COMPILE_DL_MYLIB
ZEND_GET_MODULE(mylib)
#endif
ArtemGr
  • 11,684
  • 3
  • 52
  • 85