Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > System.load / System.loadLibrary

Reply
Thread Tools

System.load / System.loadLibrary

 
 
Philipp Kraus
Guest
Posts: n/a
 
      10-09-2011
Hello,

I use System.loadLibrary to load a shared DLL. This DLL requires other
depended DLLs. If all (under OSX DYLD_LIBRARY_PATH) is configurated the
System.loadLibrary loads my DLL and everything works fine. I have
tested the same code with the DYLD-Option is not set, so my Java code
should be break.
I would like to set the Path to the library like this code:
String[] l_libraries = { "boost_system", "mylib" };

try {
for( String i : l_libraries )
System.loadLibrary(i);
} catch (UnsatisfiedLinkError e_link1) {

File l_temp = new File(
System.getProperty("java.io.tmpdir") + "mytemp" );
if (!l_temp.isDirectory())
l_temp.mkdirs();


for( String i : l_libraries ) {
String l_lib = l_temp +
System.getProperty("file.separator") + System.mapLibraryName(i);
if
(System.getProperty("os.name").toLowerCase().index Of("mac") >= 0)
l_lib = l_lib.substring(0,
l_lib.indexOf(".jnilib")) + ".dylib";

System.load(l_lib);
}
}

My target is: try to load the library and the depended from the default
system pathes, if not exists than load the libs from
a temporary path. mylib needs a depend boost library, so I load the
boost lib first, but I get the error:

Library not loaded: libboost_system.dylib Referenced from:
/mytemp/mylib.dylib Reason: image not found

Does anybody know a tip to load all libraries first, so the Java VM can
work with them from a "fixed" path?

Thanks

Phil

 
Reply With Quote
 
 
 
 
Roedy Green
Guest
Posts: n/a
 
      10-09-2011
On Sun, 9 Oct 2011 12:45:04 +0200, Philipp Kraus
<(E-Mail Removed)> wrote, quoted or indirectly quoted
someone who said :

>
>Does anybody know a tip to load all libraries first, so the Java VM can
>work with them from a "fixed" path?


I have better luck with load than loadLibrary. To me it felt like a
bug, but I have not seen bug reports so I suspect there is a mother of
a gotcha hidden in there not yet revealed.
..
--
Roedy Green Canadian Mind Products
http://mindprod.com
It should not be considered an error when the user starts something
already started or stops something already stopped. This applies
to browsers, services, editors... It is inexcusable to
punish the user by requiring some elaborate sequence to atone,
e.g. open the task editor, find and kill some processes.

 
Reply With Quote
 
 
 
 
Roedy Green
Guest
Posts: n/a
 
      10-09-2011
On Sun, 9 Oct 2011 12:45:04 +0200, Philipp Kraus
<(E-Mail Removed)> wrote, quoted or indirectly quoted
someone who said :

>
>Does anybody know a tip to load all libraries first, so the Java VM can
>work with them from a "fixed" path?


I am not sure what you are asking. You can just load them at the
start. See http://mindprod.com/jgloss/jni.html for a number of hints
on using load and loadLibrary.
--
Roedy Green Canadian Mind Products
http://mindprod.com
It should not be considered an error when the user starts something
already started or stops something already stopped. This applies
to browsers, services, editors... It is inexcusable to
punish the user by requiring some elaborate sequence to atone,
e.g. open the task editor, find and kill some processes.

 
Reply With Quote
 
Philipp Kraus
Guest
Posts: n/a
 
      10-09-2011
On 2011-10-09 13:22:39 +0200, Roedy Green said:

> On Sun, 9 Oct 2011 12:45:04 +0200, Philipp Kraus
> <(E-Mail Removed)> wrote, quoted or indirectly quoted
> someone who said :
>
>>
>> Does anybody know a tip to load all libraries first, so the Java VM can
>> work with them from a "fixed" path?

>
> I am not sure what you are asking.


My problem is, that the System.load with a fully qualified filename
does not load my library and my depend library. If I use System.loadLibrary
with the OS path (unix LIBRARY_PATH, osx DYLD_LIBRARY_PATH)
the libs are loaded.

eg: mylib is linked again boost libraries, so I would like to load with
System.load
the boost libs first. I use the System.load command with a fqn path and
get the error
"image not found"


Thx

Phil

 
Reply With Quote
 
Roedy Green
Guest
Posts: n/a
 
      10-09-2011
On Sun, 9 Oct 2011 14:09:54 +0200, Philipp Kraus
<(E-Mail Removed)> wrote, quoted or indirectly quoted
someone who said :

>My problem is, that the System.load with a fully qualified filename
>does not load my library and my depend library. If I use System.loadLibrary
>with the OS path (unix LIBRARY_PATH, osx DYLD_LIBRARY_PATH)
>the libs are loaded.
>
>eg: mylib is linked again boost libraries, so I would like to load with
>System.load
>the boost libs first. I use the System.load command with a fqn path and
>get the error
>"image not found"


Surely loadLibrary uses load itself, so if it can do it, surely you
can too. It has to be just a matter of feeding it the magic string.

Make sure you feed a fully qualified library name, with extension. Use
native platform punctuation for extra luck.

In Forth it would be trivial to insert so some code to monitor what
strings load was being fed. I have never figured out how to pull that
off in Java. If you had such a tool, I think you could crack this
problem quite quickly.
--
Roedy Green Canadian Mind Products
http://mindprod.com
It should not be considered an error when the user starts something
already started or stops something already stopped. This applies
to browsers, services, editors... It is inexcusable to
punish the user by requiring some elaborate sequence to atone,
e.g. open the task editor, find and kill some processes.

 
Reply With Quote
 
markspace
Guest
Posts: n/a
 
      10-09-2011
On 10/9/2011 7:54 AM, Roedy Green wrote:
> In Forth it would be trivial to insert so some code to monitor what
> strings load was being fed. I have never figured out how to pull that
> off in Java. If you had such a tool, I think you could crack this
> problem quite quickly.



I seem to recall a tool on Unix system for monitoring the systems calls
made by a process. I guess you could use that on the JVM to see what
file calls where made by the JVM. Not sure how it works though.

It might be strace I'm thinking of. Not sure though, I'm no sysadmin.

 
Reply With Quote
 
Philipp Kraus
Guest
Posts: n/a
 
      10-09-2011
On 2011-10-09 18:32:08 +0200, markspace said:

> On 10/9/2011 7:54 AM, Roedy Green wrote:
>> In Forth it would be trivial to insert so some code to monitor what
>> strings load was being fed. I have never figured out how to pull that
>> off in Java. If you had such a tool, I think you could crack this
>> problem quite quickly.

>
>
> I seem to recall a tool on Unix system for monitoring the systems calls
> made by a process. I guess you could use that on the JVM to see what
> file calls where made by the JVM. Not sure how it works though.
>
> It might be strace I'm thinking of. Not sure though, I'm no sysadmin.


If I do the call with System.load("/usr/lib/libmylib.so") under Linux it works,
under OSX with System.load("/usr/lib/libmylib.dylib") it does not. OSX
seems to have the
DYLD_LIBRARY_PATH environment variable.

Phil

 
Reply With Quote
 
markspace
Guest
Posts: n/a
 
      10-09-2011
On 10/9/2011 9:41 AM, Philipp Kraus wrote:

> If I do the call with System.load("/usr/lib/libmylib.so") under Linux it
> works,
> under OSX with System.load("/usr/lib/libmylib.dylib") it does not. OSX
> seems to have the
> DYLD_LIBRARY_PATH environment variable.



And I know even less about OSX than I do about other *nix. Sorry,
you're way past where I'm comfortable giving advice.

 
Reply With Quote
 
John B. Matthews
Guest
Posts: n/a
 
      10-10-2011
In article <j6rtvg$g6t$(E-Mail Removed)>,
Philipp Kraus <(E-Mail Removed)> wrote:

> Library not loaded: libboost_system.dylib Referenced from:
> /mytemp/mylib.dylib Reason: image not found
>
> Does anybody know a tip to load all libraries first, so the Java VM
> can work with them from a "fixed" path?


The simplest approach is to let DYLD_LIBRARY_PATH include the full paths
to both mylib.dylib and libboost_system.dylib.

You can display the names and version numbers of the shared libraries
required by mylib.dylib using the -L option of otool. It may be
convenient to use the -install_name option of libtool when building
mylib.dylib. Both full and relative paths are supported. The -change
option of install_name_tool may be helpful, too. There's a related
example here:

<http://home.roadrunner.com/~jbmatthews/misc/shared.html>

--
John B. Matthews
trashgod at gmail dot com
<http://sites.google.com/site/drjohnbmatthews>
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off




Advertisments