I am currently trying to add my own written shared library to my Extension(OSB). But when i try to run ./configure --with-osb
I get the error that my lib(OSC) is not found.
My config.m4:
PHP_ARG_WITH(osb, for osb support,
[ --with-osb Include osb support])
if test "$PHP_OSB" != "no"; then
LIBNAME=osc
LIBSYMBOL=mute
PHP_CHECK_LIBRARY($LIBNAME,$LIBSYMBOL,
[
PHP_ADD_INCLUDE($OSB_DIR/include)
PHP_ADD_LIBRARY_WITH_PATH($LIBNAME, $OSB_DIR/lib, OSB_SHARED_LIBADD)
AC_DEFINE(HAVE_OSB,1,[ ])
],[
AC_MSG_ERROR([wrong $LIBNAME lib version or lib not found])
],[
-L$OSB_DIR/lib -ldl
])
PHP_SUBST(OSB_SHARED_LIBADD)
PHP_NEW_EXTENSION(osb, $ext_shared)
fi
In my extension directory i have a folder where the header of my lib is lying and a lib directory where the osc.so lies in.
But somehow I am not able to find the library itself.
PKG-Config is not a possible solution.
I tried to follow the solution of this post Linking a PHP Extension Written in C . But I dont know why it wont work for me.
Another solution I tried.
I also tried other solutions but nothing worked for me.
EDIT I am using PHP8.0
So now i got it fixed. For everyone here is the solution to this problem. Seems pretty obvious after trying many other.
So if you want to invoke your own library in Linux you want to use Libtool to generate a Library on the System which then allows to to use the PKG-Config from PHP and you are not any more forced to use Path Search and other Settings.
After that it's easy to link to this lib using a config like this:
PHP_ARG_WITH([myextension],
[for myextensionsupport],
[AS_HELP_STRING([--with-myextension],
[Include myextensionsupport])])
if test "$PHP_MYEXTENSION" != "no"; then
PKG_CHECK_MODULES([MYLIBRARY], [mylibrary])
PHP_EVAL_INCLINE($MYLIBRARY_CFLAGS)
PHP_EVAL_LIBLINE($MYLIBRARY_LIBS, MYEXTENSION_SHARED_LIBADD)
dnl If you need to check for a particular library version using
PKG_CHECK_MODULES,
dnl you can use comparison operators. For example:
dnl PKG_CHECK_MODULES([MYLIBRARY], [mylibrary>= 1.2.3])
dnl PKG_CHECK_MODULES([MYLIBRARY], [mylibrary< 3.4])
dnl PKG_CHECK_MODULES([MYLIBRARY], [mylibrary= 1.2.3])
PHP_SUBST(MYEXTENSION_SHARED_LIBADD)
AC_DEFINE(HAVE_MYEXTENSION, 1, [ Have myextension support ])
PHP_NEW_EXTENSION(myextension , file.c, $ext_shared)
fi
And then run only
phpize
./configure
make
make install # If you want to export the extension to the PHP-Source