简体   繁体   中英

LD_PRELOAD variable in JNI code

My java code calls via JNI some C++ code from a shared library (eg libtest.so). The code is instrumented with some special debugging symbols that exist it libdebug.so. When I call

LD_PRELOAD=/usr/lib/libdebug.so java com.test.myMain

the execution stops with Exception in thread "main" java.lang.UnsatisfiedLinkError

because symbols from libdebug.so are not loaded (why?).

I was wondering if it is possible to modify my code in order to PRELOAD the library inside my java code. (Of course I don't want to compile java with libdebug.so...)

System.load can be used to load any shared library, so you might try loading the debug library in a static block using System.load (before you load your JNI lib). Or try System.loadLibary("debug") before your JNI lib.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM