我正在尝试为Linux构建32位版本的Sigar。当我构建时,我的JAVA_HOME指向一个32位版本的java,并且构建似乎正在构建一个32位版本,但是当我检查构建库上的头时,它说它是一个64位库。当我尝试使用该库时,我得到一个UnsatisifiedLinkError(见下文)。
这里我试图对付内置的二进制文件:
$ java -jar sigar-bin/lib/sigar.jar version
/home/epederso/sigar-1.6/bindings/java/sigar-bin/lib/libsigar-x86-linux.so: /home/epederso/sigar-1.6/bindings/java/sigar-bin/lib/libsigar-x86-linux.so:
wrong ELF class: ELFCLASS64 (Possible cause: architecture word width mismatch)
org.hyperic.sigar.SigarException: /home/epederso/sigar-1.6/bindings/java/sigar-bin/lib/libsigar-x86-linux.so: /home/epederso/sigar-1.6/bindings/java/sigar-bin/lib/libsigar-x86-linux.so: wrong ELF class: ELFCLASS64 (Possible cause: architecture word width mismatch)
at org.hyperic.sigar.Sigar.loadLibrary(Sigar.java:172)
这是构建的库的readelf输出,显示它是ELF64。
$ readelf -h sigar-bin/lib/libsigar-x86-linux.so
ELF Header:
Magic: 7f 45 4c 46 02 01 01 00 00 00 00 00 00 00 00 00
Class: ELF64
Data: 2's complement, little endian
Version: 1 (current)
OS/ABI: UNIX - System V
ABI Version: 0
Type: DYN (Shared object file)
Machine: Advanced Micro Devices X86-64
Version: 0x1
Entry point address: 0xa1b0
Start of program headers: 64 (bytes into file)
Start of section headers: 213536 (bytes into file)
Flags: 0x0
Size of this header: 64 (bytes)
Size of program headers: 56 (bytes)
Number of program headers: 5
Size of section headers: 64 (bytes)
Number of section headers: 28
Section header string table index: 25
最后,这是构建的输出:
$ ant
Buildfile: /home/epederso/sigar-1.6/bindings/java/build.xml
jni-init:
[mkdir] Created dir: /home/epederso/sigar-1.6/bindings/java/build/classes
[echo] jni.src=linux, jni.jdk.os=linux, 32-bit
[javac] /home/epederso/sigar-1.6/bindings/java/hyperic_jni/jni-build.xml:165: warning: 'includeantruntime' was not set, defaulting to build.sysclasspath=last; set to false for repeatable builds
[javac] Compiling 6 source files to /home/epederso/sigar-1.6/bindings/java/build/classes
[javac] warning: [options] bootstrap class path not set in conjunction with -source 1.4
[javac] Note: /home/epederso/sigar-1.6/bindings/java/hyperic_jni/src/org/hyperic/jni/ArchLoader.java uses or overrides a deprecated API.
[javac] Note: Recompile with -Xlint:deprecation for details.
[javac] 1 warning
[libarch] x86-linux
[echo] java.home=/usr/java/jdk1.7.0_02_32
sigar-version:
[echo] SIGAR git revision exported
version-file:
[echo] cp ./src/org/hyperic/sigar/SigarVersion.java.in -> /home/epederso/sigar-1.6/bindings/java/build/./src/org/hyperic/sigar/SigarVersion.java
[copy] Copying 1 file to /home/epederso/sigar-1.6/bindings/java/build/src/org/hyperic/sigar
version-file:
[echo] cp ../../src/sigar_version.c.in -> /home/epederso/sigar-1.6/bindings/java/build/src/sigar_version.c
[copy] Copying 1 file to /home/epederso/sigar-1.6/bindings/java/build/src
version-file:
[echo] cp ../../src/os/darwin/Info.plist.in -> /home/epederso/sigar-1.6/bindings/java/build/src/Info.plist
[copy] Copying 1 file to /home/epederso/sigar-1.6/bindings/java/build/src
version-file:
[echo] cp ../../src/os/win32/sigar.rc.in -> /home/epederso/sigar-1.6/bindings/java/build/src/sigar.rc
[copy] Copying 1 file to /home/epederso/sigar-1.6/bindings/java/build/src
sigar.rc:
prepare-src:
[exec] javasigar_generated.c needs update
[exec] generating javasigar_generated.c
[exec] generating javasigar_generated.h
[exec] generating org/hyperic/sigar/Uptime.java
[exec] skipping org/hyperic/sigar/NetStat.java
[exec] generating org/hyperic/sigar/DirStat.java
[exec] skipping org/hyperic/sigar/CpuPerc.java
[exec] generating org/hyperic/sigar/ResourceLimit.java
[exec] generating org/hyperic/sigar/NfsServerV3.java
[exec] generating org/hyperic/sigar/FileAttrs.java
[exec] generating org/hyperic/sigar/Cpu.java
[exec] generating org/hyperic/sigar/NfsClientV2.java
[exec] generating org/hyperic/sigar/DiskUsage.java
[exec] generating org/hyperic/sigar/CpuInfo.java
[exec] generating org/hyperic/sigar/FileSystem.java
[exec] generating org/hyperic/sigar/Who.java
[exec] generating org/hyperic/sigar/Swap.java
[exec] generating org/hyperic/sigar/ProcTime.java
[exec] generating org/hyperic/sigar/FileSystemUsage.java
[exec] generating org/hyperic/sigar/ProcMem.java
[exec] generating org/hyperic/sigar/ThreadCpu.java
[exec] generating org/hyperic/sigar/NetRoute.java
[exec] generating org/hyperic/sigar/ProcStat.java
[exec] generating org/hyperic/sigar/NetInterfaceConfig.java
[exec] generating org/hyperic/sigar/NetInfo.java
[exec] generating org/hyperic/sigar/SysInfo.java
[exec] generating org/hyperic/sigar/Mem.java
[exec] generating org/hyperic/sigar/NfsClientV3.java
[exec] generating org/hyperic/sigar/DirUsage.java
[exec] generating org/hyperic/sigar/NetConnection.java
[exec] generating org/hyperic/sigar/Tcp.java
[exec] generating org/hyperic/sigar/NetInterfaceStat.java
[exec] generating org/hyperic/sigar/ProcCred.java
[exec] generating org/hyperic/sigar/ProcFd.java
[exec] generating org/hyperic/sigar/ProcCredName.java
[exec] generating org/hyperic/sigar/ProcCpu.java
[exec] generating org/hyperic/sigar/NfsServerV2.java
[exec] generating org/hyperic/sigar/ProcState.java
[exec] generating org/hyperic/sigar/ProcExe.java
jni-compile:
jni-cc:
[mkdir] Created dir: /home/epederso/sigar-1.6/bindings/java/build/obj/x86-linux/lib
[echo] jni libname=sigar-x86-linux
[cc] 13 total files to be compiled.
[cc] Starting link
jni-lib-copy:
[mkdir] Created dir: /home/epederso/sigar-1.6/bindings/java/sigar-bin/lib
[copy] Copying 2 files to /home/epederso/sigar-1.6/bindings/java/sigar-bin/lib
copy-includes:
[mkdir] Created dir: /home/epederso/sigar-1.6/bindings/java/sigar-bin/include
[copy] Copying 5 files to /home/epederso/sigar-1.6/bindings/java/sigar-bin/include
build-jni:
compile:
[javac] /home/epederso/sigar-1.6/bindings/java/build.xml:102: warning: 'includeantruntime' was not set, defaulting to build.sysclasspath=last; set to false for repeatable builds
[javac] Compiling 181 source files to /home/epederso/sigar-1.6/bindings/java/build/classes
[javac] warning: [options] bootstrap class path not set in conjunction with -source 1.4
[javac] /home/epederso/sigar-1.6/bindings/java/src/org/hyperic/sigar/shell/ShellIntHandler.java:21: warning: Signal is internal proprietary API and may be removed in a future release
[javac] import sun.misc.Signal;
[javac] ^
[javac] /home/epederso/sigar-1.6/bindings/java/src/org/hyperic/sigar/shell/ShellIntHandler.java:22: warning: SignalHandler is internal proprietary API and may be removed in a future release
[javac] import sun.misc.SignalHandler;
[javac] ^
[javac] /home/epederso/sigar-1.6/bindings/java/src/org/hyperic/sigar/shell/ShellIntHandler.java:24: warning: SignalHandler is internal proprietary API and may be removed in a future release
[javac] public class ShellIntHandler implements SignalHandler {
[javac] ^
[javac] /home/epederso/sigar-1.6/bindings/java/src/org/hyperic/sigar/shell/ShellIntHandler.java:33: warning: Signal is internal proprietary API and may be removed in a future release
[javac] Signal signal;
[javac] ^
[javac] /home/epederso/sigar-1.6/bindings/java/src/org/hyperic/sigar/shell/ShellIntHandler.java:35: warning: Signal is internal proprietary API and may be removed in a future release
[javac] signal = new Signal("INT");
[javac] ^
[javac] /home/epederso/sigar-1.6/bindings/java/src/org/hyperic/sigar/shell/ShellIntHandler.java:41: warning: Signal is internal proprietary API and may be removed in a future release
[javac] Signal.handle(signal, new ShellIntHandler());
[javac] ^
[javac] /home/epederso/sigar-1.6/bindings/java/src/org/hyperic/sigar/shell/ShellIntHandler.java:47: warning: Signal is internal proprietary API and may be removed in a future release
[javac] public void handle(Signal signal) {
[javac] ^
[javac] Note: /home/epederso/sigar-1.6/bindings/java/src/org/hyperic/sigar/cmd/Ps.java uses or overrides a deprecated API.
[javac] Note: Recompile with -Xlint:deprecation for details.
[javac] 8 warnings
pack:
[jar] Building jar: /home/epederso/sigar-1.6/bindings/java/sigar-bin/lib/sigar.jar
build:
BUILD SUCCESSFUL
Total time: 10 seconds