Note that there are some explanatory texts on larger screens.

plurals
  1. PONDK undefined reference to {extern "C" function}?
    primarykey
    data
    text
    <p>I try to develop an Android app. I already managed to implement a rather small c++ function using NDK. But now I want to use a pretty large c++ library which I found on Google Docs. When I now try to build it with ndk-build tool, I get this error in cygwin console:</p> <pre><code>Compile++ thumb : ndkfoo &lt;= subspace.cpp Compile++ thumb : ndkfoo &lt;= classifier.cpp Compile++ thumb : ndkfoo &lt;= eigen.cpp Compile++ thumb : ndkfoo &lt;= image.cpp Compile++ thumb : ndkfoo &lt;= imageio.cpp Compile++ thumb : ndkfoo &lt;= local.cpp Compile++ thumb : ndkfoo &lt;= matrix.cpp Compile++ thumb : ndkfoo &lt;= sample.cpp SharedLibrary : libndkfoo.so ./obj/local/armeabi/objs/ndkfoo/eigen.o: In function `LibSubspace::geneigen(doub le*, double*, int, double*, int, bool)': U:\workspace\test/jni/eigen.cpp:91: undefined reference to `ilaenv_' U:\workspace\test/jni/eigen.cpp:96: undefined reference to `dsygv_' U:\workspace\test/jni/eigen.cpp:128: undefined reference to `dggev_' ./obj/local/armeabi/objs/ndkfoo/eigen.o: In function `LibSubspace::eigen(double* , double*, double*, int, bool)': U:\workspace\test/jni/eigen.cpp:55: undefined reference to `ilaenv_' U:\workspace\test/jni/eigen.cpp:58: undefined reference to `dsyev_' collect2: ld returned 1 exit status make: *** [obj/local/armeabi/libndkfoo.so] Error 1 </code></pre> <p>The Code of this function is as follow:</p> <pre><code>#include &lt;stdio.h&gt; #include &lt;stdlib.h&gt; #include &lt;math.h&gt; #include &lt;float.h&gt; #include &lt;assert.h&gt; #include &lt;string.h&gt; #include "eigen.h" extern "C" int ilaenv_(int *ispec, const char *name__, const char *opts, int *n1, int *n2, int *n3, int *n4, int name_len, int opts_len); extern "C" int dsyev_(const char *jobz, const char *uplo, int *n, double *a, int *lda, double *w, double *work, int *lwork, int *info); extern "C" int dsygv_(int *itype, const char *jobz, const char *uplo, int * n, double *a, int *lda, double *b, int *ldb, double *w, double *work, int *lwork, int *info); extern "C" int dggev_(const char *jobvl, const char *jobvr, int *n, double * a, int *lda, double *b, int *ldb, double *alphar, double *alphai, double *beta, double *vl, int *ldvl, double *vr, int *ldvr, double *work, int *lwork, int *info); namespace LibSubspace { int eigen(double* A, double* V, double* E, int n, bool verbose) { int info; int ispec = 1; int lwork; lwork = (ilaenv_(&amp;ispec,"DSYEV","U",&amp;n,&amp;n,&amp;n,&amp;n,5,1)+2)*n; double *work = (double *)malloc(lwork*sizeof(double)); memcpy(V,A,n*n*sizeof(double)); dsyev_("V","U",&amp;n,V,&amp;n,E,work,&amp;lwork,&amp;info); free(work); //check the return value if(info!=0) { if(verbose) { printf("Error computing eigenvectors: "); if(info&gt;0) { printf("Algorithm failed to converge\n"); } else if(info&lt;0) { printf("Illegal argument\n"); } else { printf("Unknown error\n"); } } return 0; } return 1; } int geneigen(double *A, double *B, int n, double *W, int algorithm, bool verbose) { //getting the optimal lwork int ispec = 1; int lwork; int info; switch(algorithm) { case EIGEN_CHOL: { //computing eigenvectors lwork = (ilaenv_(&amp;ispec,"DSYGV","U",&amp;n,&amp;n,&amp;n,&amp;n,5,1)+2)*n; double *work = (double *)malloc(lwork*sizeof(double)); int problemType = 1; char job = 'V'; char uplo = 'U'; dsygv_(&amp;problemType,&amp;job,&amp;uplo,&amp;n,A,&amp;n,B,&amp;n,W,work,&amp;lwork,&amp;info); free(work); //check the return value if(info!=0) { if(verbose) { printf("Error computing eigenvectors: "); if(info&gt;n) { printf("Matrix B is not positive definite\n"); } else if(info&lt;=n) { printf("The problem failed to converge\n"); } else if(info&lt;0) { printf("Illegal argument\n"); } else { printf("Unknown error\n"); } } return 0; } } break; case EIGEN_QZ: { //more general algorithm double *alphar = (double *)malloc(n*sizeof(double)); double *alphai = (double *)malloc(n*sizeof(double)); double *beta = (double *)malloc(n*sizeof(double)); double *VR = (double *)malloc(n*n*sizeof(double)); lwork = 8*n; double *work = (double *)malloc(lwork*sizeof(double)); dggev_("N","V",&amp;n,A,&amp;n,B,&amp;n,alphar,alphai,beta, NULL,&amp;n,VR,&amp;n,work,&amp;lwork,&amp;info); //eigenvalues for(long i=0;i&lt;n;i++) { if(beta[i]!=0) { W[i] = alphar[i]/beta[i]; } else W[i] = 0; } //eigenvectors for(long i=0;i&lt;n;i++) { for(long j=0;j&lt;n;j++) { A[i*n+j] = VR[i*n+j]; } } free(alphar); free(alphai); free(beta); free(VR); free(work); if(info!=0) { printf("Error computing eigenvectors: "); if(info&lt;0) { printf("Illegal argument\n"); } else if(info&lt;=n) { printf("QZ iteration failed\n"); } else { printf("Unknown error\n"); } return 0; } } break; } return 1; } } //namespace </code></pre> <p>Unfortunatly I absolutly DONT understand why these errors occur. I am not much familiar with C++, thats why I wanted to use NDK in the hope of not having to change anything of the existing library.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload