天天看點

“undefined JNI_GetCreatedJavaVM”和“File format not recognized”錯誤原因分析

如果編譯時,報如下所示錯誤:

../../third-party/hadoop/lib/libhdfs.a(jni_helper.c.o): In function `getGlobalJNIEnv':

/root/hadoop-2.4.0-src/hadoop-hdfs-project/hadoop-hdfs/src/main/native/libhdfs/jni_helper.c:446: undefined reference to `JNI_GetCreatedJavaVMs'

/root/hadoop-2.4.0-src/hadoop-hdfs-project/hadoop-hdfs/src/main/native/libhdfs/jni_helper.c:505: undefined reference to `JNI_CreateJavaVM'

是因為連結時,沒有加上庫檔案libjvm.so。加上libjvm.so重編譯,如果又遇到如下所示的錯誤:

../../third-party/libjvm.so: file not recognized: File format not recognized

這問題是因為libjvm.so不能被識别,libjvm.so的版本過高導緻的

nm ../../third-party/libjvm.so | grep JNI_CreateJavaVM

nm: ../../third-party/libjvm.so: 不可識别的檔案格式

檢視nm的版本:

nm --version

GNU nm 2.16.91.0.5 20051219 (SUSE Linux)

Copyright 2005 Free Software Foundation, Inc.

本程式是自由軟體;您可以按照 GNU 通用公共許可證

的條款對其進行再發行。本程式沒有任何擔保。

現在換成高一點的版本試試:

./nm --version

GNU nm 2.17.50.0.6-20.el5 20061020

This program is free software; you may redistribute it under the terms of

the GNU General Public License.  This program has absolutely no warranty.

./nm libjvm.so | grep JNI_CreateJavaVM

00000000006307c0 T JNI_CreateJavaVM

實際應用中,編譯雖然存在此問題,但運作時,可以使用更高版本的libjvm.so。