G++ create a share library which depends on GDAL

Viewed 21

I follow this tutorial: https://www.baeldung.com/jni and I am trying to also use GDAL. This is the cpp file:

#include <jni.h>
#include <gdal.h>
#include <ogr_geometry.h>
#include <util_gdal_GDAL.h>

JNIEXPORT jdoubleArray JNICALL Java_util_gdal_GDAL_CurveToLinestringPoints
(JNIEnv* env, jobject, jdouble x0, jdouble y0, jdouble z0, jdouble x1, 
    jdouble y1, jdouble z1, jdouble x2, jdouble y2, jdouble z2, jint bHasZ, 
    jdouble dfMaxAngleStepSizeDegrees, jstring papszOptions)
{
    const char* const papszOptionsCharPointer = env->GetStringUTFChars(papszOptions, NULL);
    OGRLineString* lineString = OGRGeometryFactory::curveToLineString(x0, y0, z0, x1,
        y1, z1, x2, y2, z2, bHasZ,
        dfMaxAngleStepSizeDegrees, &papszOptionsCharPointer);

    int sizeOfLineString = lineString->getNumPoints();
    //to do
    //const int sizeOfTheArray = bHasZ == 1 ? sizeOfLineString * 3 : sizeOfLineString * 2;
    double listOfCoordintes[20];

    int j = 0;
    for (int i = 1; i < lineString->getNumPoints(); i++)
    {
        listOfCoordintes[j] = lineString->getX(i);
        listOfCoordintes[++j] = lineString->getY(i);
        if (bHasZ) {
            listOfCoordintes[++j] = lineString->getZ(i);
        }
        j++;
    }

    jdoubleArray returnArray = env->NewDoubleArray(4);
    env->SetDoubleArrayRegion(returnArray, 0, 20, listOfCoordintes);
    return returnArray;
}

this is the header:

/* DO NOT EDIT THIS FILE - it is machine generated */
#include <jni.h>
/* Header for class util_gdal_GDAL */

#ifndef _Included_util_gdal_GDAL
#define _Included_util_gdal_GDAL
#ifdef __cplusplus
extern "C" {
#endif
    /*
     * Class:     util_gdal_GDAL
     * Method:    CurveToLinestringPoints
     * Signature: (DDDDDDDDDIDLjava/lang/String;)[D
     */
    JNIEXPORT jdoubleArray JNICALL Java_util_gdal_GDAL_CurveToLinestringPoints
    (JNIEnv*, jobject, jdouble, jdouble, jdouble, jdouble, jdouble, jdouble, jdouble, jdouble, jdouble, jint, jdouble, jstring);

#ifdef __cplusplus
}
#endif
#endif

I used the follow command to compile:

g++ -c -I"%JAVA_HOME%"\include -I"%JAVA_HOME%"\include\win32 -I. -IC:\Users\Daniela\Projects\gdal-3.5.1\ogr  -IC:\Users\Daniela\Projects\gdal-3.5.1\port -IC:\Users\Daniela\Projects\gdal-3.5.1\apps -IC:\Users\Daniela\Projects\gdal-3.5.1\gcore -IC:\Users\Daniela\Projects\gdal-3.5.1 util_gdal_GDAL.cpp -o util_gdal_GDAL.o

And then I am trying to create the share library:

g++ -shared -o gdalTest.dll util_gdal_GDAL.o C:\Users\Daniela\Projects\gdal-3.5.1\gdal305_d.dll
C:/Strawberry/c/bin/../lib/gcc/x86_64-w64-mingw32/8.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: util_gdal_GDAL.o:util_gdal_GDAL.cpp:(.text+0xe0): undefined reference to `OGRGeometryFactory::curveToLineString(double, double, double, double, double, double, double, double, double, int, double, char const* const*)'
C:/Strawberry/c/bin/../lib/gcc/x86_64-w64-mingw32/8.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: util_gdal_GDAL.o:util_gdal_GDAL.cpp:(.text+0x1ca): undefined reference to `OGRSimpleCurve::getZ(int) const'
collect2.exe: error: ld returned 1 exit status

Can you help me to solve these error please? Thank you

0 Answers
Related