为啥直接都可以!
root@52acd6c79e97:/home/huxiang_j/work/jni/jni_opencv# g++ -I$JAVA_HOME/include/ -I$JAVA_HOME/include/linux -shared -fPIC -o libmyjni.so source.cpp source.cpp: In function '_jstring* Java_jniOpencv_jniCanny(JNIEnv*, jobject, jstring)': source.cpp:27:58: warning: converting 'false' to pointer type for argument 2 of 'const char* JNIEnv_::GetStringUTFChars(jstring, jboolean*)' [-Wconversion-null] const char * str_in = env->GetStringUTFChars(js, false); ^ root@52acd6c79e97:/home/huxiang_j/work/jni/jni_opencv# g++ -I/usr/local/include/opencv -I/usr/local/include -L/usr/local/lib -lopencv_core -lopencv_imgproc -lopencv_highgui -I$JAVA_HOME/include/ -I$JAVA_HOME/include/linux -shared -fPIC -o libmyjni.so source.cpp source.cpp: In function '_jstring* Java_jniOpencv_jniCanny(JNIEnv*, jobject, jstring)': source.cpp:27:58: warning: converting 'false' to pointer type for argument 2 of 'const char* JNIEnv_::GetStringUTFChars(jstring, jboolean*)' [-Wconversion-null] const char * str_in = env->GetStringUTFChars(js, false); ^血泪史
root@4cd44daf2b17:/home/huxiang_312/work/jni/jni_opencv# g++ source.cpp -I/usr/local/include/opencv -I/usr/local/include -L/usr/local/lib -lopencv_core -lopencv_imgproc -lopencv_highgui -I$JAVA_HOME/include/ -I$JAVA_HOME/include/linux -shared -fPIC -o libmyjni.so啊啊啊
root@4cd44daf2b17:/home/huxiang_312/work/jni/jni_opencv# ldd libmyjni.so linux-vdso.so.1 => (0x00007ffc977ad000) libopencv_core.so.2.4 => /usr/local/lib/libopencv_core.so.2.4 (0x00007f645c663000) libopencv_imgproc.so.2.4 => /usr/local/lib/libopencv_imgproc.so.2.4 (0x00007f645c173000) libopencv_highgui.so.2.4 => /usr/local/lib/libopencv_highgui.so.2.4 (0x00007f645bd46000) libstdc++.so.6 => /usr/lib/x86_64-linux-gnu/libstdc++.so.6 (0x00007f645ba42000) libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007f645b82c000) libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f645b466000) libcudart.so.7.5 => /usr/local/cuda/lib64/libcudart.so.7.5 (0x00007f645b208000) libz.so.1 => /lib/x86_64-linux-gnu/libz.so.1 (0x00007f645afef000) libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007f645add0000) librt.so.1 => /lib/x86_64-linux-gnu/librt.so.1 (0x00007f645abc8000) libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007f645a8c2000) libpng12.so.0 => /lib/x86_64-linux-gnu/libpng12.so.0 (0x00007f645a69b000) /lib64/ld-linux-x86-64.so.2 (0x00007f645ce6c000) libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007f645a497000) root@4cd44daf2b17:/home/huxiang_312/work/jni/jni_opencv# mv libmyjni.so libjniOpencv.so root@4cd44daf2b17:/home/huxiang_312/work/jni/jni_opencv# cp libjniOpencv.so ../TestNativeCode/bin/ root@4cd44daf2b17:/home/huxiang_312/work/jni/jni_opencv# ls jniOpencv.class jniOpencv.h jniOpencv.java libjniOpencv.so source.cpp root@4cd44daf2b17:/home/huxiang_312/work/jni/jni_opencv# java jniOpencv Exception in thread "main" java.lang.UnsatisfiedLinkError: no jniOpencv in java.library.path at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1867) at java.lang.Runtime.loadLibrary0(Runtime.java:870) at java.lang.System.loadLibrary(System.java:1122) at jniOpencv.main(jniOpencv.java:6) root@4cd44daf2b17:/home/huxiang_312/work/jni/jni_opencv# cp libjniOpencv.so ../TestNativeCode/bin/ root@4cd44daf2b17:/home/huxiang_312/work/jni/jni_opencv# ls jniOpencv.class jniOpencv.h jniOpencv.java libjniOpencv.so source.cpp root@4cd44daf2b17:/home/huxiang_312/work/jni/jni_opencv# java jniOpencv Exception in thread "main" java.lang.UnsatisfiedLinkError: no jniOpencv in java.library.path at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1867) at java.lang.Runtime.loadLibrary0(Runtime.java:870) at java.lang.System.loadLibrary(System.java:1122) at jniOpencv.main(jniOpencv.java:6) root@4cd44daf2b17:/home/huxiang_312/work/jni/jni_opencv# cd .. root@4cd44daf2b17:/home/huxiang_312/work/jni# ls TestNativeCode TestOencv_3_12 canny g++_opencv jni_abc libmyjni.so TestNativeCode_3_12 Testopencv cpp java jni_opencv src root@4cd44daf2b17:/home/huxiang_312/work/jni# cd TestNativeCode root@4cd44daf2b17:/home/huxiang_312/work/jni/TestNativeCode# ls bin libmyjni.so libnativeCode.so src com_wwj_nativecode_TestNativeCode.h libmyjni1.so nativeCode.so com_wwj_nativecode_TestNativeCode1.h libmyjni_312opencvtest.so source.cpp root@4cd44daf2b17:/home/huxiang_312/work/jni/TestNativeCode# cd bin/ root@4cd44daf2b17:/home/huxiang_312/work/jni/TestNativeCode/bin# ls com com_wwj_nativecode_TestNativeCode.h libjniOpencv.so source.cpp root@4cd44daf2b17:/home/huxiang_312/work/jni/TestNativeCode/bin# rm libjniOpencv.so root@4cd44daf2b17:/home/huxiang_312/work/jni/TestNativeCode/bin# cp ../ .classpath libmyjni1.so .project libmyjni_312opencvtest.so .settings/ libnativeCode.so bin/ nativeCode.so com_wwj_nativecode_TestNativeCode.h source.cpp com_wwj_nativecode_TestNativeCode1.h src/ libmyjni.so root@4cd44daf2b17:/home/huxiang_312/work/jni/TestNativeCode/bin# cp ../../jni_opencv/ jniOpencv.class jniOpencv.h jniOpencv.java libjniOpencv.so source.cpp root@4cd44daf2b17:/home/huxiang_312/work/jni/TestNativeCode/bin# cp ../../jni_opencv/libjniOpencv.so . root@4cd44daf2b17:/home/huxiang_312/work/jni/TestNativeCode/bin# ls com com_wwj_nativecode_TestNativeCode.h libjniOpencv.so source.cpp root@4cd44daf2b17:/home/huxiang_312/work/jni/TestNativeCode/bin# cd .. root@4cd44daf2b17:/home/huxiang_312/work/jni/TestNativeCode# cd .. root@4cd44daf2b17:/home/huxiang_312/work/jni# ls TestNativeCode TestOencv_3_12 canny g++_opencv jni_abc libmyjni.so TestNativeCode_3_12 Testopencv cpp java jni_opencv src root@4cd44daf2b17:/home/huxiang_312/work/jni# cd jni_opencv/ root@4cd44daf2b17:/home/huxiang_312/work/jni/jni_opencv# ls jniOpencv.class jniOpencv.h jniOpencv.java libjniOpencv.so source.cpp root@4cd44daf2b17:/home/huxiang_312/work/jni/jni_opencv# java jniOpencv Exception in thread "main" java.lang.UnsatisfiedLinkError: no jniOpencv in java.library.path at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1867) at java.lang.Runtime.loadLibrary0(Runtime.java:870) at java.lang.System.loadLibrary(System.java:1122) at jniOpencv.main(jniOpencv.java:6) root@4cd44daf2b17:/home/huxiang_312/work/jni/jni_opencv# ldd libjniOpencv.so linux-vdso.so.1 => (0x00007fff1ed13000) libopencv_core.so.2.4 => /usr/local/lib/libopencv_core.so.2.4 (0x00007f0a9459c000) libopencv_imgproc.so.2.4 => /usr/local/lib/libopencv_imgproc.so.2.4 (0x00007f0a940ac000) libopencv_highgui.so.2.4 => /usr/local/lib/libopencv_highgui.so.2.4 (0x00007f0a93c7f000) libstdc++.so.6 => /usr/lib/x86_64-linux-gnu/libstdc++.so.6 (0x00007f0a9397b000) libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007f0a93765000) libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f0a9339f000) libcudart.so.7.5 => /usr/local/cuda/lib64/libcudart.so.7.5 (0x00007f0a93141000) libz.so.1 => /lib/x86_64-linux-gnu/libz.so.1 (0x00007f0a92f28000) libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007f0a92d09000) librt.so.1 => /lib/x86_64-linux-gnu/librt.so.1 (0x00007f0a92b01000) libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007f0a927fb000) libpng12.so.0 => /lib/x86_64-linux-gnu/libpng12.so.0 (0x00007f0a925d4000) /lib64/ld-linux-x86-64.so.2 (0x00007f0a94da5000) libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007f0a923d0000) root@4cd44daf2b17:/home/huxiang_312/work/jni/jni_opencv# export LD_LIBRARY_PATH=/home/huxiang_j/work/jni/jni_opencv root@4cd44daf2b17:/home/huxiang_312/work/jni/jni_opencv# java jniOpencv Exception in thread "main" java.lang.UnsatisfiedLinkError: no jniOpencv in java.library.path at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1867) at java.lang.Runtime.loadLibrary0(Runtime.java:870) at java.lang.System.loadLibrary(System.java:1122) at jniOpencv.main(jniOpencv.java:6) root@4cd44daf2b17:/home/huxiang_312/work/jni/jni_opencv# export LD_LIBRARY_PATH=/home/huxiang_312/work/jni/jni_opencv root@4cd44daf2b17:/home/huxiang_312/work/jni/jni_opencv# java jniOpencv hello jniOpencv reading/home/huxiang_j/data/1.jpgnow read successful! canny now! write now! write successful! tem1:/home/huxiang_j/data/1.jpg tem2:/home/huxiang_j/data/canny.jpg /home/huxiang_j/data/canny.jpg