【5】修改j2me_cldc/kvm/VmUnix/build/Makefile文件
(1)先改变其只读属性
[iyunv@localhost linux-test]# cd j2me_cldc/kvm
[iyunv@localhost kvm]# chmod u+w VmUnix/build/Makefile
(2)修改VmUnix/build下的Makefile,定位到文件开始处,修改如下: export PLATFORM=linux
TOP=../../..
incl? $(TOP)/build/Makefile.inc
ifeq ($(PLATFORM), linux)
export GCC=tr
endif
(3)定位到需要定位到95行,指定交叉编译器,修改如下:
ifeq ($(GCC), tr) CC = arm-linux-gcc
CFLAGS = -Wall $(CPPFLAGS) $(ROMFLAGS) $(OTHER_FLAGS)
DEBUG_FLAG = -g
OPTIMIZE_FLAG = -O2
FP_OPTIMIZE_FLAG =
else
CC = cc
CFLAGS = -Xa $(CPPFLAGS) $(ROMFLAGS) $(OTHER_FLAGS)
DEBUG_FLAG = -g -xsb
OPTIMIZE_FLAG = -xO2
FP_OPTIMIZE_FLAG =
endif
修改完后保存退出。
【6】修改j2me_cldc/kvm/VmUnix/src/runtime_md.c文件
(1)改变其只读属性
[iyunv@localhost build]# cd ../src
[iyunv@localhost src]# chmod u+w runtime_md.c
(2)把这个文件中void InitializeFloatingPoint()函数中的下面两句注释掉
[iyunv@localhost src]# vim runtime_md.c
定位到171行,修改如下:
void InitializeFloatingPoint() {
#if defined(LINUX) && PROCESSOR_ARCHITECTURE_X86
/* Set the precision FPU to do le precision */ // fpu_control_t cw = (_FPU_DEFAULT & ~_FPU_EXTENDED) | _FPU_DO LE;
// _FPU_SETCW(cw);
#endif
}
保存退出。
【7】修改j2me_cldc/tools/preverifier/build/linux目录下的Makefile
[iyunv@localhost ~]# cd linux-test/j2me_cldc/tools/preverifier/build/linux
[iyunv@localhost linux]# chmod u+w Makefile
[iyunv@localhost linux]# vim Makefile
定位到39行附近,修改如下:
CC = gcc
LD = gcc
DEBUG_FLAG = LDFLAGS = -l iconv
ifeq ($(DEBUG), tr)
DEBUG_FLAG = -g
endif
加入上面一行的目的是引入iconv库,不然在编译是会出现如下错误:
convert_md.o: In function `open_iconv':
convert_md.c:(.text+0x16): undefined reference to `libiconv_open'
convert_md.o: In function `native2utf8':
convert_md.c:(.text+0x239): undefined reference to `libiconv'
convert_md.c:(.text+0x276): undefined reference to `libiconv_close'
convert_md.o: In function `utf2native':
convert_md.c:(.text+0x365): undefined reference to `libiconv'
convert_md.c:(.text+0x3a2): undefined reference to `libiconv_close'
collect2: ld 返回 1
make: *** [preverify] 错误 1
【6】修改j2me_cldc/api目录下的Makefile,使其向下兼容1.4版本
需要先改变其只读属性
[iyunv@localhost api]# chmod u+w Makefile
然后打开j2me_cldc/api/Makefile,定位到16行,修改如下:
DEBUGFLAG=":none"
endif JAVAC = javac -source 1.4
ifneq ($(findstring win, $(PLATFORM)),)
这样修改的目的是使其向下兼容1.4版本,不然在编译时出现如下错误:
src/java/lang/Object.java:132: cannot access java.lang.StringBuilder
class file for java.lang.StringBuilder not found
return getClass().getName() + "@" + Integer.toHexString(hashCode());
网上说问题是出在几个String相加原因是JDK1.5太新,wtk2.2只能用JDK1.4.2的。JDK1.5使用StringBuilder类来代替JDK1.4中的StringB?r类。
【7】进入j2me_cldc/build/linux目录编译
[iyunv@localhost j2me_cldc]# cd build/linux
[iyunv@localhost linux]# make
... ...
src/java/lang/Object.java:132: cannot access java.lang.StringBuilder
class file for java.lang.StringBuilder not found
return getClass().getName() + "@" + Integer.toHexString(hashCode());
^
1 error
94 warnings
make[1]: *** [compilefiles] Error 1
make[1]: Leaving directory `/root/linux-test/j2me_cldc/api'
make: *** [all] 错误 1
【8】在/usr/lib目录下建立libiconv库文件
因为gcc默认的库文件路径为/usr/lib,需要将/usr/local/lib目录下的libiconv.so,libiconv.so.2,libiconv.so.2.5.0三个文件复制到此目录下或者在此目录先建立到/usr/local/lib/libiconv.so的软连接。不然会出现下面错误:
... ...
../tools/preverifier/build/linux/preverify -d classes tmpclasses
../tools/preverifier/build/linux/preverify: error while loading shared libraries: libiconv.so.2: cannot open shared object file: No s h file or directory
make[1]: *** [compilefiles] Error 1
make[1]: Leaving directory `/root/linux-test/j2me_cldc/api'
make: *** [all] 错误 1
【9】修改j2me_cldc/tools/jcc/src/util目录下ClassReader.java
需要先改变其只读属性
[iyunv@localhost api]# chmod u+w Makefile
然后打开其目录下的ClassReader.java,定位到85行修改如下:
p lic int
readZip (String fileName, Vector done) throws IOException
{
int i = 0;
ZipFile zf = new ZipFile(fileName);
Enumeration myenum = zf.entries();
while (myenum.hasMoreElements()) {
ZipEntry ent = (ZipEntry)myenum.nextElement();
String name = ent.getName();
if (!ent.isDirectory() &&
不然会出现如下错误:
... ...
src/util/ClassReader.java:85: as of release 5, 'enum' is a keyword, and may not be used as an identifier
(use -source 1.4 or lower to use 'enum' as an identifier)
Enumeration enum = zf.entries();
^
src/util/ClassReader.java:86: as of release 5, 'enum' is a keyword, and may not be used as an identifier
(use -source 1.4 or lower to use 'enum' as an identifier)
while (enum.hasMoreElements()) {
^
src/util/ClassReader.java:87: as of release 5, 'enum' is a keyword, and may not be used as an identifier
(use -source 1.4 or lower to use 'enum' as an identifier)
ZipEntry ent = (ZipEntry)enum.nextElement();
... ...
【10】参考Memo for Explanting KVM to ARM-Linux,针对如下错误需要安装低版本的编译器。
... ...
../../../kvm/VmCommon/src/verifierUtil.c: In function 'verifyClass':
../../../kvm/VmCommon/src/verifierUtil.c:547: error: invalid storage class for function 'Vfy_verifyMethod'
../../../kvm/VmCommon/src/verifierUtil.c:571: warning: implicit declaration of function 'Vfy_verifyMethod'
../../../kvm/VmCommon/src/verifierUtil.c: At top level:
../../../kvm/VmCommon/src/verifierUtil.c:1595: error: static declaration of 'Vfy_verifyMethod' follows non-static declaration
../../../kvm/VmCommon/src/verifierUtil.c:571: note: previous implicit declaration of 'Vfy_verifyMethod' was here
../../../kvm/VmCommon/src/verifierUtil.c: In function 'Vfy_verifyMethod':
../../../kvm/VmCommon/src/verifierUtil.c:1598: error: invalid storage class for function 'Vfy_checkNewInstr tions'
../../../kvm/VmCommon/src/verifierUtil.c:1633: warning: implicit declaration of function 'Vfy_checkNewInstr tions'
../../../kvm/VmCommon/src/verifierUtil.c: At top level:
../../../kvm/VmCommon/src/verifierUtil.c:1671: error: conflicting types for 'Vfy_checkNewInstr tions'
../../../kvm/VmCommon/src/verifierUtil.c:1633: note: previous implicit declaration of 'Vfy_checkNewInstr tions' was here
make[1]: *** [obj/verifierUtil.o] Error 1
make[1]: Leaving directory `/root/linux-test/j2me_cldc/kvm/VmUnix/build'
make: *** [all] 错误 1
[iyunv@localhost linux]#
(1)下载arm-linux-gcc-3.3.2.tar.bz2 : http://code.google.com/p/mini4020/downloads/detail?name=3.3.2.tar.bz2&can=2&q=label%3AMini4020
(2)修改第【4】中的Makefile,修改如下:
ifeq ($(GCC), tr) CC = /usr/local/arm/3.3.2/arm-linux/bin/gcc
CFLAGS = -Wall $(CPPFLAGS) $(ROMFLAGS) $(OTHER_FLAGS)
DEBUG_FLAG = -g
OPTIMIZE_FLAG = -O2
FP_OPTIMIZE_FLAG =
【11】进入j2me_cldc/kvm/VmUnix/build编译
[iyunv@localhost src]# cd ../build
[iyunv@localhost build]# make
... ...
Linking ... kvm
make[1]: Leaving directory `/root/linux-test/j2me_cldc/kvm/VmUnix/build'
<<<Finished Recursively making ../../kvm/VmUnix/build all.
[iyunv@localhost linux]#
OK,编译成功。
【12】查看下面两个重要文件
[iyunv@localhost ~]# file /root/linux-test/j2me_cldc/kvm/VmUnix/build/kvm
/root/linux-test/j2me_cldc/kvm/VmUnix/build/kvm: ELF 32-bit LSB executable, ARM, version 1 (ARM),for GNU/Linux 2.0.0, dynamically linked (uses shared libs), for GNU/Linux 2.0.0, not stripped
[iyunv@localhost ~]# file /root/linux-test/j2me_cldc/tools/preverifier/build/linux/preverify
/root/linux-test/j2me_cldc/tools/preverifier/build/linux/preverify: ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV), for GNU/Linux 2.6.9, dynamically linked (uses shared libs), for GNU/Linux 2.6.9,not stripped
[iyunv@localhost ~]#
可以看到,生成的kvm可执行文件是用来在目标板上运行java程序的,生成的preverify是用来预校验用。
【13】kvm验证测试
(1)进入到/root/java目录下,在linux主机上编译上面【1】jdk的测试文件helloworld.java
[iyunv@localhost ~]# cd /root/java
[iyunv@localhost java]# javac helloworld.java
[iyunv@localhost java]
(2)将编译生成的j2me_cldc/tools/preverifier/build/linux/preverify文件复制到linux主机/bin目录下
[iyunv@localhost ~]# cp linux-test/j2me_cldc/tools/preverifier/build/linux/preverify /bin
将linux-test/j2me_cldc/tools/jcc目录下classes.zip 和classesUnix.zip 分别解压到/root/java目录的classes 和classesUnix目录下
[iyunv@localhost ~]# cd linux-test/j2me_cldc/tools/jcc
[iyunv@localhost jcc]# unzip classes.zip -d /root/java/classes/
[iyunv@localhost jcc]# unzip classesUnix.zip -d /root/java/classesUnix/