我有一个非常小的.so文件(可在这里: https ://docs.google.com/leaf?id=0B4MxFm-ACB3INjhkMjhlNzktYzkxYy00Zjk5LTk0Y2MtZDE2MWQ2MzY1OWUy &hl=zh_CN& authkey =CMrJguwN )
我正在尝试在RHEL上将其加载到Java中,并且Java main
只是冻结(没有错误或exception)。 我有在LD_LIBRARY_PATH上的.so文件的目录,所以我知道它实际上是试图加载它。
任何想法如何我可以解决这个问题?
public class SmallTester { public static void main(String[] args){ for(String s: System.getenv("LD_LIBRARY_PATH").split(":")){ System.out.println(s); } System.loadLibrary("TestAda"); System.out.println("Here"); } }
编辑:
基于下面的post,我做了一个strace ..它看起来像它一遍又一遍地重复这个电话(我不知道这是什么意思?):
[pid 31464] clock_gettime(CLOCK_MONOTONIC, {3605675, 624255544}) = 0 [pid 31464] gettimeofday({1306417113, 168967}, NULL) = 0 [pid 31464] clock_gettime(CLOCK_MONOTONIC, {3605675, 624435576}) = 0 [pid 31464] clock_gettime(CLOCK_MONOTONIC, {3605675, 624518205}) = 0 [pid 31464] gettimeofday({1306417113, 169216}, NULL) = 0 [pid 31464] clock_gettime(CLOCK_REALTIME, {1306417113, 169306590}) = 0 [pid 31464] futex(0x88b3f04, FUTEX_WAIT_PRIVATE, 1, {0, 49909410}) = -1 ETIMEDOUT (Connection timed out)
以下是日志的完整版本: https : //docs.google.com/leaf?id=0B4MxFm-ACB3IYzdhZWIwNWEtYjUzMS00NGM5LWEzZjQtYzMzOWE3MWNhYWQ0&hl=zh_CN&authkey=CJ-Lv_wG
编辑2:我试图加载与JNA库:
public class SmallTesterJNA { public interface CLibrary extends Library { CLibrary INSTANCE1 = (CLibrary) Native.loadLibrary("TestAda", // <<< our library goes here CLibrary.class); } public static void main(String[] args){ for(String s: System.getenv("LD_LIBRARY_PATH").split(":")){ System.out.println(s); } System.loadLibrary(CLibrary.INSTANCE1.toString()); System.out.println("Here"); } }
这里是输出结果..它看起来非常相似: https : //docs.google.com/leaf?id = 0B4MxFm-ACB3IYzdhZWIwNWEtYjUzMS00NGM5LWEzZjQtYzMzOWE3MWNhYWQ0&hl=zh_CN&authkey = CJ-Lv_wG
EDIT2:
这是我的gcore输出附加到进程..不知道这是什么告诉我:
(no debugging symbols found) (no debugging symbols found) [Thread debugging using libthread_db enabled] [New Thread 0xb7fb26c0 (LWP 8326)] [New Thread 0x7fa8eb90 (LWP 8340)] [New Thread 0x7fe2db90 (LWP 8339)] [New Thread 0x7fe7eb90 (LWP 8338)] [New Thread 0x7feffb90 (LWP 8337)] [New Thread 0x800afb90 (LWP 8336)] [New Thread 0x80100b90 (LWP 8335)] [New Thread 0x80351b90 (LWP 8334)] [New Thread 0x803a2b90 (LWP 8333)] [New Thread 0x80423b90 (LWP 8332)] [New Thread 0x8066db90 (LWP 8331)] [New Thread 0x806eeb90 (LWP 8330)] [New Thread 0x8076fb90 (LWP 8329)] [New Thread 0x807f0b90 (LWP 8328)] [New Thread 0xb7474b90 (LWP 8327)] (no debugging symbols found) (no debugging symbols found) (no debugging symbols found) (no debugging symbols found) (no debugging symbols found) (no debugging symbols found) (no debugging symbols found) (no debugging symbols found) (no debugging symbols found) (no debugging symbols found) (no debugging symbols found) (no debugging symbols found) (no debugging symbols found) (no debugging symbols found) 0xb7fcd402 in __kernel_vsyscall () Saved corefile core.8326
如果我不得不猜测,我会说一个可能的罪魁祸首是共享对象的初始化代码。
抓取你的JVM进程的核心转储(使用gcore
)或者附加gdb
来获取堆栈跟踪的结果。
我通常在gdb之前尝试strace(跟踪所有的系统调用)。 执行:
strace -f java SmallTester > logfile 2>&1
你会在日志文件中得到很多信息,最后一部分是最有趣的。 您将找到jvm进程查找您的TestAda.so文件,并查看是否成功加载了.so文件。 如果这不起作用,恢复到gdb。
看看你的C ++代码中的JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *vm, void *reserved)
函数。 它可能有一个无限循环:)也尝试定义,如果它尚未定义。
有关JNI_OnLoad
详细信息,请参阅此处 。