/usr/bin/ld: cannot find -ljvm:during compiling jni project
Asked Answered
I

2

0

i'm compiling a jni project.here is detail of the problem i encountering: r

oot@kaiwiiho:/home/kaiwii/svn# make
gcc -shared build/utimebufClass.o build/contextClass.o build/fsClass.o build/javafuse_jni.o build/statClass.o build/statvfsClass.o build/fileinfoClass.o build/conninfoClass.o -o build/libjavafuse.so
gcc -g -Wall `pkg-config --cflags fuse` -Iinclude -I/usr/java/jdk1.6.0_31/include -I/usr/java/jdk1.6.0_31/include/linux `pkg-config --libs fuse`  -L/usr/java/packages/lib/i386 -L/lib -L/usr/lib -ljvm -Lbuild -ljavafuse src/javafuse.c -o javafuse
src/javafuse.c: In function ‘javafuse_readdir’:
src/javafuse.c:2194:22: warning: cast from pointer to integer of different size
src/javafuse.c:2195:25: warning: cast from pointer to integer of different size
src/javafuse.c:2207:15: warning: cast to pointer from integer of different size
src/javafuse.c:2208:18: warning: cast to pointer from integer of different size
src/javafuse.c:2256:16: warning: cast from pointer to integer of different size
src/javafuse.c:2257:19: warning: cast from pointer to integer of different size
src/javafuse.c:2271:15: warning: cast to pointer from integer of different size
src/javafuse.c:2272:18: warning: cast to pointer from integer of different size
src/javafuse.c: In function ‘javafuse_releasedir’:
src/javafuse.c:2332:12: warning: assignment from incompatible pointer type
src/javafuse.c: In function ‘javafuse_fsyncdir’:
src/javafuse.c:2420:12: warning: assignment from incompatible pointer type
/usr/bin/ld: cannot find -ljvm
collect2: ld returned 1 exit status
make: *** [javafuse] 错误 1
root@kaiwiiho:/home/kaiwii/svn# ldconfig
root@kaiwiiho:/home/kaiwii/svn# gedit /etc/ld.so.conf
root@kaiwiiho:/home/kaiwii/svn# make
gcc -shared build/utimebufClass.o build/contextClass.o build/fsClass.o build/javafuse_jni.o build/statClass.o build/statvfsClass.o build/fileinfoClass.o build/conninfoClass.o -o build/libjavafuse.so
gcc -g -Wall `pkg-config --cflags fuse` -Iinclude -I/usr/java/jdk1.6.0_31/include -I/usr/java/jdk1.6.0_31/include/linux `pkg-config --libs fuse`  -L/usr/java/packages/lib/i386 -L/lib -L/usr/lib -ljvm -Lbuild -ljavafuse src/javafuse.c -o javafuse
src/javafuse.c: In function ‘javafuse_readdir’:
src/javafuse.c:2194:22: warning: cast from pointer to integer of different size
src/javafuse.c:2195:25: warning: cast from pointer to integer of different size
src/javafuse.c:2207:15: warning: cast to pointer from integer of different size
src/javafuse.c:2208:18: warning: cast to pointer from integer of different size
src/javafuse.c:2256:16: warning: cast from pointer to integer of different size
src/javafuse.c:2257:19: warning: cast from pointer to integer of different size
src/javafuse.c:2271:15: warning: cast to pointer from integer of different size
src/javafuse.c:2272:18: warning: cast to pointer from integer of different size
src/javafuse.c: In function ‘javafuse_releasedir’:
src/javafuse.c:2332:12: warning: assignment from incompatible pointer type
src/javafuse.c: In function ‘javafuse_fsyncdir’:
src/javafuse.c:2420:12: warning: assignment from incompatible pointer type
/usr/bin/ld: cannot find -ljvm
collect2: ld returned 1 exit status
make: *** [javafuse] 错误 1

And for sake that the the libjvm.so have aready exisited in the /usr/lib,i directly make a conf file,/etc/ld.so.conf.d/my.conf:

/usr/lib
/usr/local/lib

and then i use command ldconfig. but unfortunately,i still encounter the same problem yet. Any idea?thx

Importunacy answered 31/3, 2012 at 3:53 Comment(0)
D
2

This command:

gcc -g -Wall `pkg-config --cflags fuse` -Iinclude \
  -I/usr/java/jdk1.6.0_31/include \
  -I/usr/java/jdk1.6.0_31/include/linux `pkg-config --libs fuse`  \
  -L/usr/java/packages/lib/i386 -L/lib -L/usr/lib -ljvm -Lbuild -ljavafuse \
  src/javafuse.c -o javafuse

is incorrect. The order of libraries and sources on the link line matters, and your order is wrong.

But that's not what your problem is right now. You insist that libjvm.so exists in /usr/lib, but have shown no evidence that it does. What does ls -l /usr/lib/libjvm.so actually print?

Note that it would be highly unusual to find libjvm.so in /usr/lib. Usually one would expect to find it in e.g. /usr/java/packages/lib/i386/server, and you are not searching that directory.

Update:

well. libjvm.so is not actually in the /usr/lib but in /usr/java/jdk1.6.0_31/jre/lib/i386/server

In that case, you need to add -L/usr/java/jdk1.6.0_31/jre/lib/i386/server to your link line.

And i gedit a conf file ...

Obviously that's not sufficient.

Diptych answered 31/3, 2012 at 6:17 Comment(3)
well.libjvm.so is not actually in the /usr/lib but in /usr/java/jdk1.6.0_31/jre/lib/i386/server.And i gedit a conf file in the /usr/java/jdk1.6.0_31/jre/lib/i386/server containing,/usr/java/jdk1.6.0_31/jre/lib/i386/server.use command,ldconfig and reboot.but it still prompt the same error.Importunacy
thanks...it works...actually I used straight forwardly this - " gcc -g -I /usr/lib/jvm/java-6-sun-1.6.0.26/include -I /usr/lib/jvm/java-6-sun-1.6.0.26/include/linux -L /usr/lib/jvm/java-6-sun-1.6.0.26/jre/lib/i386/server -ljvm CallJVM.c " and a.out was created. Then I need to link it with libjvm.so present in server folder as mentioned in post.Tontine
I found a similar problem when installing python javabridge module: /usr/lib64/gcc/x86_64-suse-linux/4.5/../../../../x86_64-suse-linux/bin/ld: cannot find -ljvm. I worked it around creating a symbolic link: cd /usr/lib; ln -s /usr/lib64/jvm/java-1_6_0-ibm-1.6.0/jre/lib/amd64/default/libjvm.so libjvm.soCatadromous
H
0

The error is coming because JAVA_HOME & LD_LIBRARY_PATH is not consistent for Linux.So after analysis i discover that JAVA_HOME and LD_LIBRARY_PATH is resetting everytime whenever the terminal window is closed. So setting the JAVA_HOME permanently resolved the error like:- JAVA_HOME=/usr/java/latest PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin:/usr/java/latest/bin:/bin:/sbin:/usr/lib64/qt-3.3/bin LD_LIBRARY_PATH=/usr/java/jdk1.8.0_111/jre/lib/amd64/server:/usr/local/lib:/usr/lib64:/usr/lib:/usr/local/lib64:

Heavyset answered 16/12, 2016 at 4:8 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.