20938

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

Question:

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

Answer1:

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 <a href="http://webpages.charter.net/ppluzhnikov/linker.html" rel="nofollow">matters</a>, 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 <em>that</em> directory.

Update:

<blockquote>

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

</blockquote>

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

<blockquote>

And i gedit a conf file ...

</blockquote>

Obviously that's not sufficient.

Answer2:

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:

Recommend

  • Android & calling methods that current API doesnt have
  • Exception while connecting to hive through jdbc
  • GWT unit testing with cookies
  • internal error occurred during: “PHP CodeSniffer”. in zend studio 10.0
  • How to get datas from List (Java)?
  • Confusing java.lang.NoSuchMethodError
  • Smali syntax for DalvikVM opcodes
  • IBM Worklight 6.0 - Migration Issue after importing a project
  • How to get this Method object via reflection?
  • Spring Data JPA Repositories
  • How do I fix VerifyError when running PowerMock in Java 8
  • How do I fix VerifyError when running PowerMock in Java 8
  • PDFStamper fails on several PDF files (itext 5.5.1)
  • C++ JNI crashes/hangs when doing any IO/Streams
  • How can I use a TypedActor in a Java application?
  • Input Chinese characters not correctly echoed in ESS
  • How To Modify Constant Pool Using ASM?
  • c3p0 ResultSet.unwrap throws an AbstractMethodError
  • proto2 with Spark cannot run
  • Does javac also inline?
  • Why does my println in rdd prints the string of elements?
  • RavenDB indexing errors
  • Multiple Left Join LINQ-to-entities
  • Suqueries in select clause with JPA
  • Thread 1: EXC_BAD_ACCESS (code =1 address = 0x0)
  • Default parameter as generic type
  • Object and struct member access and address offset calculation
  • How to assign byte[] as a pointer in C#
  • How to view images from protected folder with php?
  • C: Incompatible pointer type initializing
  • Display images in Django
  • Resize panoramic image to fixed size
  • Importing jscolor library in angular 2
  • Function pointer “assignment from incompatible pointer type” only when using vararg ellipsis
  • Run Powershell script from inside other Powershell script with dynamic redirection to file
  • Binding checkboxes to object values in AngularJs
  • How can i traverse a binary tree from right to left in java?
  • Net Present Value in Excel for Grouped Recurring CF
  • jQuery Masonry / Isotope and fluid images: Momentary overlap on window resize
  • How to load view controller without button in storyboard?