Conor, I suspect that you should add an extern "C" { void GDALRegisterMe(); } line at the beginning of your cpp file.
-- Thomas On Tue, Jan 12, 2021 at 12:56 PM Conor McIndoe <conormcind...@gmail.com> wrote: > Hello developers, > > I am just learning the ropes with GDAL so apologies if some of this is > quite far off. Also apologies in advance for the essay :) > > I am trying to register a pixel function, written in C++, in order to > produce a VRT and eventually a TIF from some input TIFs. I am trying to > follow an thread from this mailing list > (https://lists.osgeo.org/pipermail/gdal-dev/2011-May/028742.html) to > make GDAL aware of a shared library which contains and registers the > pixel function. Hopefully there is some clear error here which one of > you can spot? > > I have adapted the example found at the VRT reference page > (https://gdal.org/drivers/raster/vrt.html) to produce a function which > sets every pixel equal to 1 (just to test the workflow): > > // src/gdalPixelFunctions.cpp > > #include "gdal.h" > #include "cpl_conv.h" > #include "gdal_priv.h" > > #include <iostream> > > CPLErr OneFunction( > void **papoSources, int nSources, void *pData, > int nXSize, int nYSize, GDALDataType eSrcType, > GDALDataType eBufType, int nPixelSpace, int nLineSpace > ) > { > int ii, iLine, iCol; > double pix_val; > double x0, x3, x4, x8; > > if(nSources != 4) return CE_Failure; > > for(iLine = 0; iLine < nYSize; iLine++) > { > for(iCol = 0; iCol < nXSize; iCol++) > { > ii = iLine * nXSize + iCol; > > /* Source raster pixels may be obtained with SRCVAL macro */ > x0 = SRCVAL(papoSources[0], eSrcType, ii); > x3 = SRCVAL(papoSources[1], eSrcType, ii); > x4 = SRCVAL(papoSources[2], eSrcType, ii); > x8 = SRCVAL(papoSources[3], eSrcType, ii); > > pix_val = 1; > > GDALCopyWords( > &pix_val, > GDT_Float64, > 0, > ((GByte *)pData) + nLineSpace * iLine + iCol * > nPixelSpace, > eBufType, > nPixelSpace, > 1 > ); > } > } > > return CE_None; > } > > void GDALRegisterMe() > { > std::cout << "Inside GDALRegisterME()" << std::endl; > GDALAddDerivedBandPixelFunc("OneFunction", OneFunction); > } > > > Compilation: > > g++ -std=c++20 -fPIC -lgdal -c src/gdalPixelFunctions.cpp -o > build/gdal_pixelFunctions.o > > g++ -lgdal -shared build/gdal_pixelFunctions.o -o > build/gdal_pixelFunctions.so > > export GDAL_DRIVER_PATH="/path/to/build" > > > Attempting to call: > > gdal_translate testVrt.vrt testVrt.tif > > (where testVrt.vrt references the OneFunction pixel function) results in > the following error messages: > > ERROR 1: /path/to/build/gdal_pixelFunctions.so: undefined symbol: > GDALRegisterMe > ERROR 1: /path/to/build/gdal_pixelFunctions.so: undefined symbol: > GDALRegister_pixelFunctions > > I have also tried registering by defining a void > GDALRegister_pixelFunctions() but with the same issue. I assume this > error means that GDAL is looking in the shared library for these two > register functions and failing to find them? > > Thank you for your help and sorry for the long post! > > _______________________________________________ > gdal-dev mailing list > gdal-dev@lists.osgeo.org > https://lists.osgeo.org/mailman/listinfo/gdal-dev >
_______________________________________________ gdal-dev mailing list gdal-dev@lists.osgeo.org https://lists.osgeo.org/mailman/listinfo/gdal-dev