通过 JNI 执行 OpenCV 本机函数的问题
Posted
技术标签:
【中文标题】通过 JNI 执行 OpenCV 本机函数的问题【英文标题】:Issue executing OpenCV native functions via JNI 【发布时间】:2015-04-10 00:27:08 【问题描述】:我正在尝试通过 Ubuntu 上的 Java 本机接口运行本机 OpenCV 函数。最终我想要完成的是使用 OpenCV 默认版本中可用的bagofwords
函数,但目前我正在尝试使用这个接口测试运行简单的函数。
所以,我有以下带有相关本机函数的 Java 文件。
class OpenCVSample
static
System.loadLibrary("Bridge1");
public native int BridgeFunction();
public static void main(String[] args)
OpenCVSample b = new OpenCVSample();
b.BridgeFunction();
这是我的 C++ Bridge
文件。
#include "OpenCVSample.h"
#include <string.h>
#include <cv.h>
JNIEXPORT jint JNICALL Java_OpenCVSample_BridgeFunction(JNIEnv *env, jobject obj)
IplImage *img = cvCreateImage( cvSize( 640, 480 ), IPL_DEPTH_8U, 1 );
return 1;
int main()
现在正如我所提到的,我在 Ubuntu 上执行此操作,所以我首先使用以下命令将 OpenCV 编译到带有 gcc
的 jdk 的共享库中。
g++ -shared -o libBridge1.so Bridge1.cpp -fPIC -I/usr/lib/jvm/java-1.7.0-openjdk-amd64/include -I/usr/lib/jvm/java-1.7.0-openjdk-amd64/include/linux -I/var/opencv/opencv/include/opencv
-I/var/opencv/opencv/modules/core/include
-I/var/opencv/opencv/modules/imgproc/include
-I/var/opencv/opencv/modules/features2d/include
-I/var/opencv/opencv/modules/flann/include
-I/var/opencv/opencv/modules/calib3d/include
-I/var/opencv/opencv/modules/objdetect/include
-I/var/opencv/opencv/modules/legacy/include
-I/var/opencv/opencv/modules/highgui/include
然后创建一个名为libBridge1.so
的共享库。现在,当我尝试运行 Java 文件本身时出现问题,我收到以下错误。
java:符号查找错误:/var/tests/oc/libBridge1.so:未定义符号:cvCreateImage
我对此进行了相当多的研究,几乎可以确定我正在正确创建共享库,所以不明白为什么会出现此错误,谁能解释一下?
----------------------------------- 编辑 -----------------------------------
感谢用户 Andrew Henle 和 James Black 的建议。我已经继续并使用以下命令链接了各个库。
g++ -shared -o libBridge1.so OpenCVSample.cpp -fPIC -I/usr/lib/jvm/java-1.7.0-openjdk-amd64/include -I/usr/lib/jvm/java-1.7.0-openjdk-amd64/include/linux -I/var/opencv/opencv/include -I/var/opencv/opencv/include/opencv -I/var/opencv/opencv/modules/core/include -I/var/opencv/opencv/modules/imgproc/include -I/var/opencv/opencv/modules/photo/include -I/var/opencv/opencv/modules/objdetect/include -L/var/opencv/opencv/build/lib -lopencv_core -L/var/opencv/opencv/build/lib -lopencv_imgproc -L/var/opencv/opencv/build/lib -lopencv_highgui -L/var/opencv/opencv/build/lib -lopencv_objdetect -L/var/opencv/opencv/build/lib -lopencv_features2d -L/var/opencv/opencv/build/lib -lopencv_video -L/var/opencv/opencv/build/lib -lopencv_core249
该库似乎可以编译,但现在问题似乎是它充满了undefined references
。在libBridge1.so
上运行ld
命令时,我收到以下错误流。
ld: warning: cannot find entry symbol _start; not setting start address
libBridge1.so: undefined reference to `ippicviMirror_32s_C4R'
libBridge1.so: undefined reference to `ippicviTranspose_8u_C1R'
libBridge1.so: undefined reference to `ippicviNormDiff_Inf_16u_C4R'
libBridge1.so: undefined reference to `ippicviSub_8u_C1RSfs'
libBridge1.so: undefined reference to `ippicviTranspose_32s_C1IR'
libBridge1.so: undefined reference to `ippicviSum_32f_C3R'
libBridge1.so: undefined reference to `pthread_mutex_trylock'
libBridge1.so: undefined reference to `ippicviMean_16u_C1MR'
libBridge1.so: undefined reference to `ippicviTranspose_16s_C3R'
libBridge1.so: undefined reference to `ippicviNorm_L2_16s_C3R'
libBridge1.so: undefined reference to `ippicviXor_8u_C1R'
libBridge1.so: undefined reference to `ippicviMirror_8u_C4R'
libBridge1.so: undefined reference to `ippicviNorm_Inf_16u_C1R'
libBridge1.so: undefined reference to `ippicviNormDiff_L2_16u_C1R'
libBridge1.so: undefined reference to `ippicviNormDiff_Inf_16u_C3CMR'
libBridge1.so: undefined reference to `ippicviNormDiff_L2_32f_C3R'
libBridge1.so: undefined reference to `ippicviNorm_L2_32f_C1R'
libBridge1.so: undefined reference to `ippicviNormDiff_L1_16s_C3R'
libBridge1.so: undefined reference to `ippicviNorm_L1_8s_C1MR'
libBridge1.so: undefined reference to `ippicviSet_16u_C3MR'
libBridge1.so: undefined reference to `gzeof'
libBridge1.so: undefined reference to `ippicviNormDiff_Inf_32f_C1MR'
libBridge1.so: undefined reference to `ippicviTranspose_16u_C3IR'
libBridge1.so: undefined reference to `ippicviSum_16u_C4R'
libBridge1.so: undefined reference to `ippicviAbsDiff_8u_C1R'
libBridge1.so: undefined reference to `ippicviNormRel_L2_8u_C1MR'
libBridge1.so: undefined reference to `ippicviAbsDiff_16u_C1R'
libBridge1.so: undefined reference to `ippicvsMinEvery_16u'
libBridge1.so: undefined reference to `ippicvMalloc'
libBridge1.so: undefined reference to `ippicviNormDiff_L1_32f_C1MR'
libBridge1.so: undefined reference to `ippicviMirror_16u_C3IR'
libBridge1.so: undefined reference to `ippicviConvert_8s32f_C1R'
libBridge1.so: undefined reference to `ippicviNormDiff_L2_16s_C4R'
libBridge1.so: undefined reference to `ippicvsFlip_32f_I'
libBridge1.so: undefined reference to `ippicviNormDiff_L2_16u_C3R'
libBridge1.so: undefined reference to `ippicviNormDiff_Inf_8u_C3CMR'
libBridge1.so: undefined reference to `ippicviTranspose_16u_C1IR'
libBridge1.so: undefined reference to `ippicviSub_16u_C1RSfs'
libBridge1.so: undefined reference to `ippicviSet_16u_C4MR'
libBridge1.so: undefined reference to `ippicviTranspose_8u_C3IR'
libBridge1.so: undefined reference to `ippicviNorm_L1_16u_C3R'
libBridge1.so: undefined reference to `gzopen'
libBridge1.so: undefined reference to `ippicviTranspose_16u_C1R'
libBridge1.so: undefined reference to `ippicviMean_32f_C3CMR'
libBridge1.so: undefined reference to `ippicviNormDiff_L2_32f_C1MR'
libBridge1.so: undefined reference to `pthread_mutexattr_settype'
libBridge1.so: undefined reference to `gzclose'
libBridge1.so: undefined reference to `ippicviNorm_L2_16u_C4R'
libBridge1.so: undefined reference to `ippicviCompare_16s_C1R'
libBridge1.so: undefined reference to `ippicviMax_8u_C1R'
libBridge1.so: undefined reference to `ippicviMean_16s_C3R'
libBridge1.so: undefined reference to `ippicviConvert_32f16u_C1RSfs'
libBridge1.so: undefined reference to `ippicviConvert_32s32f_C1R'
libBridge1.so: undefined reference to `ippicviNormDiff_L2_8u_C1MR'
libBridge1.so: undefined reference to `ippicviMean_8u_C1R'
libBridge1.so: undefined reference to `ippicviMirror_16s_C3R'
libBridge1.so: undefined reference to `ippicviNormDiff_L1_32f_C4R'
libBridge1.so: undefined reference to `ippicviNormRel_L1_8u_C1MR'
libBridge1.so: undefined reference to `pthread_key_create'
libBridge1.so: undefined reference to `ippicviMirror_16u_C1IR'
libBridge1.so: undefined reference to `ippicviNormRel_L2_16u_C1R'
libBridge1.so: undefined reference to `gzrewind'
libBridge1.so: undefined reference to `ippicviMirror_32s_C1R'
libBridge1.so: undefined reference to `ippicviAdd_32f_C1R'
libBridge1.so: undefined reference to `ippicviNorm_L1_8u_C1MR'
libBridge1.so: undefined reference to `ippicviNormDiff_Inf_32f_C1R'
libBridge1.so: undefined reference to `ippicviNormDiff_Inf_8u_C4R'
libBridge1.so: undefined reference to `ippicviSum_8u_C1R'
libBridge1.so: undefined reference to `ippicviNormDiff_L1_8s_C1MR'
libBridge1.so: undefined reference to `ippicviConvert_16u32s_C1R'
libBridge1.so: undefined reference to `ippicviNorm_L1_16s_C4R'
libBridge1.so: undefined reference to `ippicviConvert_16u8s_C1RSfs'
libBridge1.so: undefined reference to `ippicviMirror_16s_C4IR'
libBridge1.so: undefined reference to `ippicviNormDiff_L2_16u_C3CMR'
libBridge1.so: undefined reference to `ippicviNormRel_L1_16u_C1MR'
libBridge1.so: undefined reference to `ippicviCompare_8u_C1R'
libBridge1.so: undefined reference to `ippicviMinMaxIndx_32f_C1MR'
libBridge1.so: undefined reference to `ippicviMirror_32f_C4IR'
libBridge1.so: undefined reference to `ippicviNormDiff_Inf_32f_C4R'
libBridge1.so: undefined reference to `ippicviSum_16s_C3R'
libBridge1.so: undefined reference to `ippicviMin_32f_C1R'
libBridge1.so: undefined reference to `ippicviNorm_L1_16s_C3R'
libBridge1.so: undefined reference to `ippicviNormDiff_L2_16s_C1R'
libBridge1.so: undefined reference to `ippicviNormDiff_L1_32f_C1R'
libBridge1.so: undefined reference to `dlsym'
libBridge1.so: undefined reference to `ippicviNormRel_L2_16s_C1R'
libBridge1.so: undefined reference to `ippicviCopy_32s_C3MR'
libBridge1.so: undefined reference to `ippicviConvert_16u8u_C1R'
libBridge1.so: undefined reference to `ippicviSet_16s_C4MR'
libBridge1.so: undefined reference to `ippicviMax_16s_C1R'
libBridge1.so: undefined reference to `ippicviMinMaxIndx_8u_C1MR'
libBridge1.so: undefined reference to `pthread_once'
libBridge1.so: undefined reference to `ippicviNormRel_L2_8s_C1MR'
libBridge1.so: undefined reference to `ippicviNorm_L1_32f_C1MR'
libBridge1.so: undefined reference to `ippicviTranspose_8u_C4IR'
libBridge1.so: undefined reference to `ippicviConvert_16s32s_C1R'
libBridge1.so: undefined reference to `ippicviCopy_8u_C1R'
libBridge1.so: undefined reference to `ippicvsMinEvery_8u'
libBridge1.so: undefined reference to `ippicvsFlip_64f_I'
libBridge1.so: undefined reference to `ippicvsMaxEvery_32f'
libBridge1.so: undefined reference to `ippicviMirror_32f_C1R'
libBridge1.so: undefined reference to `ippicviNormRel_L1_16u_C1R'
libBridge1.so: undefined reference to `ippicviNormRel_L2_32f_C1MR'
libBridge1.so: undefined reference to `ippicviNorm_L1_16u_C4R'
libBridge1.so: undefined reference to `ippicviAdd_16u_C1RSfs'
libBridge1.so: undefined reference to `ippicviNorm_L2_16s_C4R'
libBridge1.so: undefined reference to `ippicviMean_8u_C1MR'
libBridge1.so: undefined reference to `ippicviNormDiff_Inf_16u_C3R'
libBridge1.so: undefined reference to `ippicviMul_16u_C1RSfs'
libBridge1.so: undefined reference to `ippicvsMaxEvery_64f'
libBridge1.so: undefined reference to `ippicviMirror_16u_C3R'
libBridge1.so: undefined reference to `ippicviTranspose_32s_C4IR'
libBridge1.so: undefined reference to `ippicviMirror_8u_C3IR'
libBridge1.so: undefined reference to `ippicviConvert_32s8u_C1R'
libBridge1.so: undefined reference to `ippicviTranspose_16s_C3IR'
libBridge1.so: undefined reference to `ippicviSum_8u_C3R'
libBridge1.so: undefined reference to `ippicviNorm_Inf_32f_C4R'
libBridge1.so: undefined reference to `ippicviTranspose_8u_C3R'
libBridge1.so: undefined reference to `ippicviMinMaxIndx_8s_C1MR'
libBridge1.so: undefined reference to `ippicviConvert_32s16u_C1RSfs'
libBridge1.so: undefined reference to `ippicviConvert_8s8u_C1Rs'
libBridge1.so: undefined reference to `ippicviNormRel_Inf_32f_C1MR'
libBridge1.so: undefined reference to `ippicviTranspose_8u_C1IR'
libBridge1.so: undefined reference to `ippicviNormDiff_Inf_8s_C3CMR'
libBridge1.so: undefined reference to `ippicviNormDiff_L1_8u_C4R'
libBridge1.so: undefined reference to `ippicvsSortAscend_8u_I'
libBridge1.so: undefined reference to `ippicviNormDiff_Inf_16u_C1MR'
libBridge1.so: undefined reference to `ippicviConvert_32f32s_C1RSfs'
libBridge1.so: undefined reference to `ippicviTranspose_16s_C1R'
libBridge1.so: undefined reference to `ippicviCopy_32s_C4MR'
libBridge1.so: undefined reference to `ippicviNormDiff_L2_8u_C3CMR'
libBridge1.so: undefined reference to `ippicviNorm_L2_16u_C3R'
libBridge1.so: undefined reference to `pthread_getspecific'
libBridge1.so: undefined reference to `ippicviSet_32s_C4MR'
libBridge1.so: undefined reference to `ippicviNorm_Inf_16u_C3R'
libBridge1.so: undefined reference to `ippicviNormDiff_L1_32f_C3R'
libBridge1.so: undefined reference to `ippicviTranspose_32s_C1R'
libBridge1.so: undefined reference to `ippicvInit'
libBridge1.so: undefined reference to `ippicviMean_8u_C3CMR'
libBridge1.so: undefined reference to `ippicviNormDiff_Inf_8u_C3R'
libBridge1.so: undefined reference to `ippicviNorm_L1_32f_C3R'
libBridge1.so: undefined reference to `pthread_mutexattr_destroy'
libBridge1.so: undefined reference to `ippicviNorm_Inf_8u_C4R'
libBridge1.so: undefined reference to `ippicviConvert_32s16s_C1RSfs'
libBridge1.so: undefined reference to `ippicviMul_16s_C1RSfs'
libBridge1.so: undefined reference to `ippicviNormDiff_Inf_8s_C1MR'
libBridge1.so: undefined reference to `ippicviNormDiff_L2_16u_C4R'
libBridge1.so: undefined reference to `ippicviMean_StdDev_8u_C3CMR'
libBridge1.so: undefined reference to `ippicviMirror_32s_C4IR'
libBridge1.so: undefined reference to `ippicviCopy_16u_C1MR'
libBridge1.so: undefined reference to `ippicviMean_StdDev_16u_C1MR'
libBridge1.so: undefined reference to `ippicviNormRel_L1_32f_C1MR'
libBridge1.so: undefined reference to `ippicviConvert_32f8s_C1RSfs'
libBridge1.so: undefined reference to `ippicviSum_16u_C1R'
libBridge1.so: undefined reference to `ippicviNormDiff_L1_8u_C1R'
libBridge1.so: undefined reference to `ippicviMirror_8u_C3R'
libBridge1.so: undefined reference to `ippicviNorm_L1_16u_C1R'
libBridge1.so: undefined reference to `ippicviMirror_32s_C1IR'
libBridge1.so: undefined reference to `ippicviMul_32f_C1R'
libBridge1.so: undefined reference to `ippicviNormDiff_Inf_16s_C4R'
libBridge1.so: undefined reference to `ippicviTranspose_32s_C4R'
libBridge1.so: undefined reference to `ippicviConvert_32s8s_C1R'
libBridge1.so: undefined reference to `ippicviTranspose_16u_C4R'
libBridge1.so: undefined reference to `ippicviNorm_L2_16u_C1MR'
libBridge1.so: undefined reference to `ippicviNorm_Inf_16s_C4R'
libBridge1.so: undefined reference to `ippicviTranspose_32f_C4IR'
libBridge1.so: undefined reference to `ippicviNorm_L2_8u_C3R'
libBridge1.so: undefined reference to `ippicviMean_16u_C4R'
libBridge1.so: undefined reference to `ippicviTranspose_16s_C4R'
libBridge1.so: undefined reference to `ippicviMean_32f_C1R'
libBridge1.so: undefined reference to `ippicviNot_8u_C1R'
libBridge1.so: undefined reference to `ippicviNorm_Inf_8u_C3R'
libBridge1.so: undefined reference to `ippicviNorm_L2_16s_C1R'
libBridge1.so: undefined reference to `ippicviNormDiff_L2_16u_C1MR'
libBridge1.so: undefined reference to `ippicviLUTPalette_8u_C4R'
libBridge1.so: undefined reference to `ippicviMirror_16u_C4R'
libBridge1.so: undefined reference to `ippicviTranspose_32f_C1IR'
libBridge1.so: undefined reference to `ippicviNormRel_Inf_16s_C1R'
libBridge1.so: undefined reference to `ippicviMean_StdDev_16u_C3CMR'
libBridge1.so: undefined reference to `ippicviSub_16s_C1RSfs'
libBridge1.so: undefined reference to `ippicviNormDiff_L2_8u_C1R'
libBridge1.so: undefined reference to `ippicviNorm_Inf_32f_C3R'
libBridge1.so: undefined reference to `ippicviNormDiff_L1_16u_C1MR'
libBridge1.so: undefined reference to `ippicviCopy_8u_C3MR'
libBridge1.so: undefined reference to `ippicviNorm_L1_32f_C1R'
libBridge1.so: undefined reference to `ippicviMirror_32s_C3R'
libBridge1.so: undefined reference to `ippicviNormDiff_L1_16u_C3R'
libBridge1.so: undefined reference to `ippicviMean_8u_C3R'
libBridge1.so: undefined reference to `pthread_mutexattr_init'
libBridge1.so: undefined reference to `ippicviNorm_Inf_16s_C1R'
libBridge1.so: undefined reference to `ippicviConvert_16s8s_C1RSfs'
libBridge1.so: undefined reference to `ippicviNormRel_Inf_32f_C1R'
libBridge1.so: undefined reference to `ippicviNormDiff_L1_8s_C3CMR'
libBridge1.so: undefined reference to `ippicviNormRel_L2_16u_C1MR'
libBridge1.so: undefined reference to `ippicviMinMaxIndx_8s_C1R'
libBridge1.so: undefined reference to `ippicviNorm_L1_16s_C1R'
libBridge1.so: undefined reference to `ippicviMean_StdDev_8u_C3CR'
libBridge1.so: undefined reference to `ippicviSet_32f_C3MR'
libBridge1.so: undefined reference to `ippicviConvert_8s16s_C1R'
libBridge1.so: undefined reference to `ippicviAdd_8u_C1RSfs'
libBridge1.so: undefined reference to `ippicviNormDiff_Inf_32f_C3R'
libBridge1.so: undefined reference to `ippicviConvert_16u16s_C1RSfs'
libBridge1.so: undefined reference to `ippicviSet_16s_C3MR'
libBridge1.so: undefined reference to `ippicviTranspose_32f_C1R'
libBridge1.so: undefined reference to `ippicviSum_16u_C3R'
libBridge1.so: undefined reference to `ippicviMirror_16s_C3IR'
libBridge1.so: undefined reference to `ippicviNorm_Inf_8s_C1MR'
libBridge1.so: undefined reference to `ippicviConvert_8s16u_C1Rs'
libBridge1.so: undefined reference to `ippicviNorm_L2_32f_C3R'
libBridge1.so: undefined reference to `ippicviMean_16u_C1R'
libBridge1.so: undefined reference to `ippicviNorm_L1_8u_C3R'
libBridge1.so: undefined reference to `ippicviCopy_8u_C3P3R'
libBridge1.so: undefined reference to `ippicviCopy_16u_C3MR'
libBridge1.so: undefined reference to `ippicviNorm_L2_16u_C1R'
libBridge1.so: undefined reference to `ippicviNormDiff_L2_8u_C3R'
libBridge1.so: undefined reference to `ippicviSum_8u_C4R'
libBridge1.so: undefined reference to `ippicviNormDiff_L1_16u_C1R'
libBridge1.so: undefined reference to `ippicviMean_32f_C1MR'
libBridge1.so: undefined reference to `ippicviTranspose_16s_C4IR'
libBridge1.so: undefined reference to `ippicviMirror_8u_C1IR'
libBridge1.so: undefined reference to `ippicviTranspose_32f_C4R'
libBridge1.so: undefined reference to `ippicviMean_StdDev_32f_C1MR'
libBridge1.so: undefined reference to `ippicviNormDiff_L1_16s_C4R'
libBridge1.so: undefined reference to `ippicviNormRel_Inf_16u_C1R'
libBridge1.so: undefined reference to `ippicviSum_16s_C1R'
libBridge1.so: undefined reference to `ippicviNormDiff_Inf_16s_C3R'
libBridge1.so: undefined reference to `ippicviMean_16u_C3R'
libBridge1.so: undefined reference to `ippicviDotProd_16u64f_C1R'
libBridge1.so: undefined reference to `ippicviCompare_16u_C1R'
libBridge1.so: undefined reference to `ippicviMean_StdDev_16u_C3CR'
libBridge1.so: undefined reference to `ippicviNorm_L2_8u_C4R'
libBridge1.so: undefined reference to `ippicviMirror_8u_C4IR'
libBridge1.so: undefined reference to `ippicvsDotProd_64f'
libBridge1.so: undefined reference to `ippicviSet_32f_C4MR'
libBridge1.so: undefined reference to `ippicvsMinEvery_32f'
libBridge1.so: undefined reference to `ippicviNormDiff_L1_32f_C3CMR'
libBridge1.so: undefined reference to `ippicviNorm_L2_8u_C1MR'
libBridge1.so: undefined reference to `ippicviNorm_Inf_16s_C3R'
libBridge1.so: undefined reference to `ippicviSum_32f_C4R'
libBridge1.so: undefined reference to `ippicviNormRel_L1_32f_C1R'
libBridge1.so: undefined reference to `ippicviTranspose_16u_C4IR'
libBridge1.so: undefined reference to `ippicviNorm_Inf_8u_C1MR'
libBridge1.so: undefined reference to `ippicviSub_32f_C1R'
libBridge1.so: undefined reference to `ippicviMax_16u_C1R'
libBridge1.so: undefined reference to `ippicviMean_StdDev_8u_C1MR'
libBridge1.so: undefined reference to `ippicviTranspose_32f_C3R'
libBridge1.so: undefined reference to `ippicviSum_32f_C1R'
libBridge1.so: undefined reference to `ippicviMinMaxIndx_8u_C1R'
libBridge1.so: undefined reference to `ippicviMin_16u_C1R'
libBridge1.so: undefined reference to `ippicviNormDiff_L2_8s_C1MR'
libBridge1.so: undefined reference to `ippicviSet_32s_C3MR'
libBridge1.so: undefined reference to `ippicviNorm_L2_8s_C1MR'
libBridge1.so: undefined reference to `ippicviMax_32f_C1R'
libBridge1.so: undefined reference to `ippicviNorm_L2_32f_C1MR'
libBridge1.so: undefined reference to `ippicviNormDiff_L1_16u_C4R'
libBridge1.so: undefined reference to `ippicviNorm_L1_16u_C1MR'
libBridge1.so: undefined reference to `ippicviNorm_L1_32f_C4R'
libBridge1.so: undefined reference to `ippicviNormDiff_L2_32f_C3CMR'
libBridge1.so: undefined reference to `ippicviCopy_8u_C4P4R'
libBridge1.so: undefined reference to `ippicvsMaxEvery_16u'
libBridge1.so: undefined reference to `ippicviNormRel_Inf_8s_C1MR'
libBridge1.so: undefined reference to `ippicviNormDiff_Inf_8u_C1R'
libBridge1.so: undefined reference to `ippicviTranspose_16s_C1IR'
libBridge1.so: undefined reference to `ippicviCopy_8u_C1MR'
libBridge1.so: undefined reference to `ippicviSet_32s_C1MR'
libBridge1.so: undefined reference to `ippicvsFlip_8u_I'
libBridge1.so: undefined reference to `ippicviConvert_8u32s_C1R'
libBridge1.so: undefined reference to `ippicviNormRel_Inf_8u_C1MR'
libBridge1.so: undefined reference to `ippicviTranspose_32s_C3R'
libBridge1.so: undefined reference to `ippicvsMinEvery_64f'
libBridge1.so: undefined reference to `ippicviTranspose_16u_C3R'
libBridge1.so: undefined reference to `ippicviConvert_8u16s_C1R'
libBridge1.so: undefined reference to `ippicviCopy_32s_C1MR'
libBridge1.so: undefined reference to `ippicviConvert_8u8s_C1RSfs'
libBridge1.so: undefined reference to `ippicviNormDiff_Inf_16s_C1R'
libBridge1.so: undefined reference to `ippicviDotProd_16s64f_C1R'
libBridge1.so: undefined reference to `ippicviSet_16s_C1MR'
libBridge1.so: undefined reference to `ippicviNorm_L1_8u_C1R'
libBridge1.so: undefined reference to `ippicviNorm_L2_32f_C4R'
libBridge1.so: undefined reference to `ippicviOr_8u_C1R'
libBridge1.so: undefined reference to `ippicviMirror_8u_C1R'
libBridge1.so: undefined reference to `ippicviNormDiff_L1_8u_C3R'
libBridge1.so: undefined reference to `ippicviTranspose_32s_C3IR'
libBridge1.so: undefined reference to `ippicviMirror_16s_C1R'
libBridge1.so: undefined reference to `ippicviMean_16s_C4R'
libBridge1.so: undefined reference to `ippicviMean_16s_C1R'
libBridge1.so: undefined reference to `ippicviConvert_32f8u_C1RSfs'
libBridge1.so: undefined reference to `ippicviConvert_16s32f_C1R'
libBridge1.so: undefined reference to `ippicviMin_8u_C1R'
libBridge1.so: undefined reference to `ippicviNorm_L2_8u_C1R'
libBridge1.so: undefined reference to `ippicviLUTPalette_8u_C3R'
libBridge1.so: undefined reference to `gzgets'
libBridge1.so: undefined reference to `ippicviMirror_32f_C1IR'
libBridge1.so: undefined reference to `ippicviAdd_16s_C1RSfs'
libBridge1.so: undefined reference to `ippicviMean_StdDev_32f_C3CR'
libBridge1.so: undefined reference to `ippicviConvert_8u16u_C1R'
libBridge1.so: undefined reference to `ippicviMean_StdDev_32f_C3CMR'
libBridge1.so: undefined reference to `ippicviMirror_32f_C4R'
libBridge1.so: undefined reference to `ippicviNorm_Inf_8u_C1R'
libBridge1.so: undefined reference to `ippicviMul_8u_C1RSfs'
libBridge1.so: undefined reference to `ippicviTranspose_32f_C3IR'
libBridge1.so: undefined reference to `ippicviMin_16s_C1R'
libBridge1.so: undefined reference to `ippicviNormRel_L2_8u_C1R'
libBridge1.so: undefined reference to `ippicviNormDiff_L2_32f_C4R'
libBridge1.so: undefined reference to `ippicviMirror_32s_C3IR'
libBridge1.so: undefined reference to `ippicviMirror_16s_C1IR'
libBridge1.so: undefined reference to `ippicviMean_8u_C4R'
libBridge1.so: undefined reference to `ippicviNormRel_Inf_8u_C1R'
libBridge1.so: undefined reference to `ippicviNorm_L1_8u_C4R'
libBridge1.so: undefined reference to `ippicviNormRel_Inf_16u_C1MR'
libBridge1.so: undefined reference to `ippicviNormRel_L1_8s_C1MR'
libBridge1.so: undefined reference to `ippicviMean_32f_C3R'
libBridge1.so: undefined reference to `ippicviMean_32f_C4R'
libBridge1.so: undefined reference to `ippicviMirror_32f_C3R'
libBridge1.so: undefined reference to `gzputs'
libBridge1.so: undefined reference to `ippicviMirror_32f_C3IR'
libBridge1.so: undefined reference to `ippicviAbsDiff_32f_C1R'
libBridge1.so: undefined reference to `ippicvsFlip_16u_I'
libBridge1.so: undefined reference to `ippicviNormRel_L1_16s_C1R'
libBridge1.so: undefined reference to `ippicviNormDiff_L2_32f_C1R'
libBridge1.so: undefined reference to `ippicviConvert_16s16u_C1Rs'
libBridge1.so: undefined reference to `ippicvsDotProd_32f64f'
libBridge1.so: undefined reference to `ippicviMean_StdDev_8u_C1R'
libBridge1.so: undefined reference to `ippicviMirror_16u_C1R'
libBridge1.so: undefined reference to `ippicviMinMaxIndx_16u_C1MR'
libBridge1.so: undefined reference to `ippicviNormDiff_Inf_32f_C3CMR'
libBridge1.so: undefined reference to `ippicviConvert_16u32f_C1R'
libBridge1.so: undefined reference to `ippicviNormDiff_L1_8u_C1MR'
libBridge1.so: undefined reference to `ippicvFree'
libBridge1.so: undefined reference to `ippicviNorm_Inf_32f_C1R'
libBridge1.so: undefined reference to `ippicviSet_32f_C1MR'
libBridge1.so: undefined reference to `ippicviMinMaxIndx_16u_C1R'
libBridge1.so: undefined reference to `ippicvsMaxEvery_8u'
libBridge1.so: undefined reference to `ippicviTranspose_8u_C4R'
libBridge1.so: undefined reference to `ippicviNormDiff_L2_16s_C3R'
libBridge1.so: undefined reference to `ippicviNormDiff_L2_8s_C3CMR'
libBridge1.so: undefined reference to `ippicviNormDiff_Inf_8u_C1MR'
libBridge1.so: undefined reference to `ippicviMinMaxIndx_32f_C1R'
libBridge1.so: undefined reference to `dlopen'
libBridge1.so: undefined reference to `ippicviMirror_16s_C4R'
libBridge1.so: undefined reference to `ippicviNormDiff_L2_8u_C4R'
libBridge1.so: undefined reference to `ippicviNormDiff_L1_8u_C3CMR'
libBridge1.so: undefined reference to `ippicviSum_16s_C4R'
libBridge1.so: undefined reference to `pthread_setspecific'
libBridge1.so: undefined reference to `ippicviMean_StdDev_16u_C1R'
libBridge1.so: undefined reference to `ippicviNormRel_L1_8u_C1R'
libBridge1.so: undefined reference to `ippicviMean_16u_C3CMR'
libBridge1.so: undefined reference to `ippicviCompare_32f_C1R'
libBridge1.so: undefined reference to `ippicviNorm_Inf_16u_C4R'
libBridge1.so: undefined reference to `ippicviNormRel_L2_32f_C1R'
libBridge1.so: undefined reference to `ippicviNorm_Inf_32f_C1MR'
libBridge1.so: undefined reference to `ippicviConvert_16s8u_C1R'
libBridge1.so: undefined reference to `ippicviNormDiff_Inf_16u_C1R'
libBridge1.so: undefined reference to `ippicviAnd_8u_C1R'
libBridge1.so: undefined reference to `ippicviConvert_8s32s_C1R'
libBridge1.so: undefined reference to `ippicviNormDiff_L1_16u_C3CMR'
libBridge1.so: undefined reference to `ippicviMean_StdDev_32f_C1R'
libBridge1.so: undefined reference to `ippicviConvert_8u32f_C1R'
libBridge1.so: undefined reference to `ippicviSet_16u_C1MR'
libBridge1.so: undefined reference to `ippicviDotProd_32s64f_C1R'
libBridge1.so: undefined reference to `ippicviMirror_16u_C4IR'
libBridge1.so: undefined reference to `ippicvsSortDescend_8u_I'
运行 java 文件本身时,我现在遇到了这个问题:
Exception in thread "main" java.lang.UnsatisfiedLinkError: /var/tests/oc/libBridge1.so: /var/tests/oc/libBridge1.so: undefined symbol: ippicviMinMaxIndx_16u_C1R
at java.lang.ClassLoader$NativeLibrary.load(Native Method)
at java.lang.ClassLoader.loadLibrary0(ClassLoader.java:1937)
at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1855)
at java.lang.Runtime.loadLibrary0(Runtime.java:870)
at java.lang.System.loadLibrary(System.java:1122)
at Bridge1.<clinit>(OpenCVSample.java:4)
--------------------------------- 编辑 2 ---------------------------------
经过进一步修改后,我发现了获取未定义引用的问题。我链接到了错误的核心文件。然而,问题仍然存在,只是规模较小。这是我正在使用的以下命令:
g++ -Wall -shared-libgcc -Im -o libBridge1.so Bridge1.cpp -fPIC -I/usr/lib/jvm/java-1.7.0-openjdk-amd64/include -I/usr/lib/jvm/java-1.7.0-openjdk-amd64/include/linux -I/var/opencv/opencv/include -I/var/opencv/opencv/include/opencv -I/var/opencv/opencv/modules/core/include -I/var/opencv/opencv/modules/imgproc/include -I/var/opencv/opencv/modules/photo/include -I/var/opencv/opencv/modules/objdetect/include -I/var/opencv/opencv/modules/imgcodecs/include -I/var/opencv/opencv/modules/videoio/include -I/var/opencv/opencv/modules/highgui/include -L/var/opencv/opencv/build/lib -lopencv_core249 -L/var/opencv/opencv/build/lib -lopencv_features2d -L/var/opencv/opencv/build/lib -lopencv_imgproc -I/var/opencv/opencv/build/lib
在编译过程中,我现在收到此错误:
Bridge1.cpp: In function ‘jint Java_Bridge1_BridgeFunction(JNIEnv*, jobject)’:
Bridge1.cpp:8:12: warning: unused variable ‘img’ [-Wunused-variable]
IplImage *img = cvCreateImage( cvSize( 640, 480 ), IPL_DEPTH_8U, 1 );
^
/tmp/ccqbVddx.o: In function `Java_Bridge1_BridgeFunction':
Bridge1.cpp:(.text+0x63): undefined reference to `cvCreateImage'
collect2: error: ld returned 1 exit status
【问题讨论】:
【参考方案1】:您需要将共享对象与所需的“-l...”选项链接起来,就像您正在编译一个普通的 C/C++ 可执行文件来运行相同的函数一样。
如果您执行“ldd libBridge1.so”,您应该会看到所需的库。如果您没有看到所需的库,则需要将它们添加到链接步骤中。
【讨论】:
但是如果你看一下编译指令,我已经做过了,例如:-I/var/opencv/opencv/modules/core/include
。我还在图书馆跑了ldd
,它只是说他们是statically linked
这些是包含目录,使用 -I(大写眼睛),而不是 -l(小写 ell)。您需要为共享对象添加对链接命令的引用才能运行共享对象 - 就像它是可执行文件一样。 “-L/path/to/libs -lsomelib ...”。当它正确时,如果您执行“ldd -r libBridge1.so”,您将不会看到任何错误。
-我告诉编译器你的包含在哪里,而不是你需要链接的库在哪里。 ldd 会告诉您链接到的库,但您没有链接到任何库。
我不完全明白该怎么做,我以前从未真正用 C++ 做过任何事情。只是现在我需要使用 OpenCV java 端口中不可用的特定类。你能解释一下我是怎么做到的吗?
OpenCV 的文档说什么用于链接可执行文件以运行? “-L”和“-l”(大写和小写ell)选项?您需要将这些添加到您的 gcc 命令中: gcc ... -L/path/to/libs -lOpenCV ...(假设 OpenCV 的库称为“libOpenCV.so”)【参考方案2】:
我同意 Andrew Henie 关于-l
标志的观点,因为我很好奇您的库是如何编译的。
但在您的 java 类中调用 System.loadLibrary(..)
以首先加载您的库。
那么我预计它会失败,使用ld
命令将有助于指出您缺少什么。
【讨论】:
运行ld
返回以下内容。 ld: warning: cannot find entry symbol _start; not setting start address libBridge1.so: undefined reference to
cvCreateImage' `
而ldd
只是声明文件是statically linked
嗨,James,在链接各个库后,我已经用更新的结果更新了主帖。
看起来你需要添加 -ldl -lpthread
和 ippicv 库,不管是什么。以上是关于通过 JNI 执行 OpenCV 本机函数的问题的主要内容,如果未能解决你的问题,请参考以下文章
使用 jni 和 OpenCV 创建的带有 lib 的未定义符号
当我想在sdcard JNI C ++中保存帧时,imwrite opencv函数总是返回false