问题
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
回答1:
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.
回答2:
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:
来源:https://stackoverflow.com/questions/9952889/usr-bin-ld-cannot-find-ljvmduring-compiling-jni-project