dev@grizzly.java.net

Re: [OT] Basic JNI questions/PHP implementation

From: Harsha Godugu <Harsha.Godugu_at_Sun.COM>
Date: Thu, 24 Jan 2008 00:45:29 -0800

forgot to mention... LD_LIBRARY_PATH needs to be set to the location of
other libraries. (PATH in case of win32)

Harsha Godugu wrote:

> Jeanfrancois Arcand wrote:
>
>> Hi,
>>
>> I'm currently working on a PHP's Grizzly extension via the
>> com.sun.grizzly.Adapter class, and today I've hit a wall :-). What I
>> want to do is:
>>
>> Client --> Request --> Grizzly --> PHPAdapter -- JNI Call --> libphp5.so
>>
>> Inside the PHPAdapter, I did:
>>
>>> static {
>>> System.loadLibrary("php5");
>>> }
>>
>>
>>
>> so far so good. Now problems :-) Since I'm working on linux, I need
>> to build the libphp5.so from scratch. So I've followed the
>> instruction (many many many times ;-) by building Apache2 from
>> scratch, and then build php 5 using Apache 2. At the end, I'm getting
>> the libphp5.so, which is what I need. Then, I start Grizzly HTTP
>> Server with:
>>
>> % java -Djava.library.path=/usr/local/apache2/lib/ -jar
>> grizzly-http-1.7-SNAPSHOT.jar 8080 /www/php
>>
>> And *always* get:
>>
>>> java.lang.UnsatisfiedLinkError:
>>> /usr/local/apache2/modules/libphp5.so:
>>> /usr/local/apache2/modules/libphp5.so: undefined symbol: ap_rwrite
>>> at java.lang.ClassLoader$NativeLibrary.load(Native Method)
>>> at java.lang.ClassLoader.loadLibrary0(ClassLoader.java:1751)
>>> at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1676)
>>> at java.lang.Runtime.loadLibrary0(Runtime.java:822)
>>> at java.lang.System.loadLibrary(System.java:993)
>>
>>
>>
>> Which is expected, because:
>>
>>> [jfarcand_at_localhost http]$ ldd -r
>>> /usr/local/apache2/modules/libphp5.so linux-gate.so.1 =>
>>> (0x00546000)
>>> libcrypt.so.1 => /lib/libcrypt.so.1 (0x00ae6000)
>>> librt.so.1 => /lib/librt.so.1 (0x00111000)
>>> libz.so.1 => /usr/lib/libz.so.1 (0x00125000)
>>> libresolv.so.2 => /lib/libresolv.so.2 (0x00164000)
>>> libm.so.6 => /lib/libm.so.6 (0x00177000)
>>> libdl.so.2 => /lib/libdl.so.2 (0x00f4d000)
>>> libnsl.so.1 => /lib/libnsl.so.1 (0x00b6c000)
>>> libxml2.so.2 => /usr/lib/libxml2.so.2 (0x00e21000)
>>> libc.so.6 => /lib/libc.so.6 (0x001af000)
>>> libpthread.so.0 => /lib/libpthread.so.0 (0x0019b000)
>>> /lib/ld-linux.so.2 (0x00148000)
>>> undefined symbol: ap_rwrite (/usr/local/apache2/modules/libphp5.so)
>>> undefined symbol: apr_table_set (/usr/local/apache2/modules/libphp5.so)
>>
>>
>> [cut ... more than 20]
>
>
> Hi,
>
> try loading the shared lib (.so) where ap_rwrite, apr_table_set is
> defined, first (the way you loaded libphp5.so).
> use "nm" to find the symbols in a given library (.so). and append
> the location of that library (where ap_* is defined) to
> java.library.path. That should work :-)
>
> -hg
>
>>
>> Now the ap_* stuff is from Apache2, which is probably dynamically
>> loaded when Apache2 start. Now how can I make sure the libph5.so gets
>> all its dependencies loaded from java? I did try to add the path to
>> Apache 2 *.so file to my -Djava.library.path but still get the same
>> exceptions. I did build the libphp5.so on two linux kernel and os X,
>> and always get the same exception.
>>
>> I'm probably missing something trivial :-) Any help appreciated :-)
>>
>> Thanks
>>
>> -- Jeanfrancois
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: dev-unsubscribe_at_grizzly.dev.java.net
>> For additional commands, e-mail: dev-help_at_grizzly.dev.java.net
>>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe_at_grizzly.dev.java.net
> For additional commands, e-mail: dev-help_at_grizzly.dev.java.net
>