Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / Virtual Machine / March 2005

Tip: Looking for answers? Try searching our database.

relocation error on api call from JNI to a C  .so

Thread view: 
prak - 08 Mar 2005 11:57 GMT
Hi,

  i have a C shared library a.so which internally loads another b.so.
b.so has api calls to api defined in a.so. Using JNI Loadlibrary i load
a.so which loads successfully. Then i call an api in a.so which
internally loads b.so and then when there is a api call from b.so to
one defined in a.so ,i get a runtime relocation error mentioning the
api name.

i am using unix os, gcc compiler. a.so was compiled with -shared
-rdynamic options.

please help me out.

thanks,
prah
Gordon Beaton - 08 Mar 2005 13:39 GMT
> i have a C shared library a.so which internally loads another b.so.
> b.so has api calls to api defined in a.so. Using JNI Loadlibrary i
[quoted text clipped - 5 lines]
> i am using unix os, gcc compiler. a.so was compiled with -shared
> -rdynamic options.

Presumably the JVM uses RTLD_LOCAL to load liba.so, so its symbols are
not directly visible from libb.so.

Offhand I can think of two workarounds:

1. If you specify "-f libb.so" when you build liba.so, you tell the
  linker about a's dependency on b. The effect of this is that when
  your Java program does System.loadLibrary("a"), both liba.so and
  libb.so will be loaded automatically, and you don't need to do
  dlopen("libb.so") from liba.so. Both sets of symbols will be
  directly visible from both libraries (without the need for
  dlopen(), dlsym() etc).

2. From a.so, you could pass function pointers to an initialization
  function in b.so, and let b.so access the functions through the
  pointers.

You might also consider combining or at least refactoring the two
libraries in order to avoid the circular dependency.

/gordon

Signature

[  do not email me copies of your followups  ]
g o r d o n + n e w s @  b a l d e r 1 3 . s e

prak - 09 Mar 2005 11:23 GMT
Thanks gordon, the -f option worked.

> > i have a C shared library a.so which internally loads another b.so.
> > b.so has api calls to api defined in a.so. Using JNI Loadlibrary i
[quoted text clipped - 31 lines]
> [  do not email me copies of your followups  ]
> g o r d o n + n e w s @  b a l d e r 1 3 . s e


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.