Reputation: 648
SOLVED
I just installed "sudo apt-get install gcc-multilib" and it allowed to compile succesfully using the following command:
gcc -m32 -o invoke -I$JAVA_HOME/include -I$JAVA_HOME/include/linux cCode.c $JAVA_HOME/jre/lib/i386/server/libjvm.so
Here is downloadable source code: http://cfile237.uf.daum.net/attach/247819495212DF1C07B9EB
well, first, my ubuntu is 64bit 12.04LTS. and, I installed both 64 and 32bit version of latest jdk 1.7.0_25.
I tried to compile the source code above using 32 bit library of jdk version on my 64bit Ubuntu, it shows a following error:
/usr/lib/jvm/jdk1.7.0_25_x86/jre/lib/i386/server/libjvm.so: could not read symbols: File in wrong format
collect2: ld returned 1 exit status
However, if I try to compile those source code using 64 bit library of jdk version, it compiles fine and run very well.
My problem is, as you know, how would I make it compile and run well using 32 bit version of jdk library on 64bit Ubuntu platform?
AH, before I compile, I always typed following commands on Terminal,
for 32 bit compile
export PATH=$PATH:/usr/lib/jvm/jdk1.7.0_25_x86/bin
export JAVA_HOME=/usr/lib/jvm/jdk1.7.0_25_x86
export LD_LIBRARY_PATH=$JAVA_HOME/jre/lib/i386:$JAVA_HOME/jre/lib/i386/server
for 64 bit compile
export PATH=$PATH:/usr/lib/jvm/jdk1.7.0_25_x64/bin
export JAVA_HOME=/usr/lib/jvm/jdk1.7.0_25_x64
export LD_LIBRARY_PATH=$JAVA_HOME/jre/lib/amd64:$JAVA_HOME/jre/lib/amd64/server
Upvotes: 0
Views: 1843
Reputation: 46
Here is my Makefile (make sure you have all dependent packages installed)
JDK32 = /usr/lib/jvm/java-1.7.0-openjdk-i386
JDK64 = /usr/lib/jvm/java-1.7.0-openjdk-amd64
all: invoke_amd64 invoke_x86
invoke_x86: cCode.c
$(CC) -m32 -I$(JDK32)/include $^ -L$(JDK32)/jre/lib/i386/server -ljvm -Wl,-rpath -Wl,$(JDK32)/jre/lib/i386/server -o $@
invoke_amd64: cCode.c
$(CC) -I$(JDK64)/include $^ -L$(JDK64)/jre/lib/amd64/server -ljvm -Wl,-rpath -Wl,$(JDK64)/jre/lib/amd64/server -o $@
clean:
rm invoke*
Upvotes: 0
Reputation: 7799
Install the ubuntu 32-bit compatibility library (ia32-libs
).
sudo apt-get install ia32libs
Upvotes: 0
Reputation: 206796
First of all, note that Java programs themselves are not 32-bit or 64-bit.
It does not matter if you compile your code with a 32-bit or 64-bit JDK, the resulting Java bytecode will be exactly the same. Code compiled with a 32-bit JDK will run on a 64-bit JRE and vice versa. So, you do not need to compile your code with a 32-bit and 64-bit JDK.
I don't know the exact cause of your problem, but you might somehow be mixing parts of the 32-bit and 64-bit JDK, which will not work.
Upvotes: 1