Open leonid-butenko opened 1 year ago
Can you try installing the compilers into a new environment and activate that first?
Can you try installing the compilers into a new environment and activate that first?
Same result:
$> docker run -it --rm -v /work:/work condaforge/miniforge3
(base) root@87026bdd2af5:/# conda create -n test -y gcc_linux-64 gxx_linux-64 libgdal
...
Preparing transaction: done
Verifying transaction: done
Executing transaction: done
#
# To activate this environment, use
#
# $ conda activate test
#
# To deactivate an active environment, use
#
# $ conda deactivate
(base) root@87026bdd2af5:/# conda activate test
(test) root@87026bdd2af5:/# cd /work
(test) root@87026bdd2af5:/work# $GXX -I$CONDA_PREFIX/include -L$CONDA_PREFIX/lib -lgdal test_gdal.cpp -o test_gdal
test_gdal.cpp: In constructor 'Interpolator2D::Interpolator2D(const std::vector<double>&, const std::vector<double>&, const std::vector<std::vector<double> >&)':
test_gdal.cpp:39:25: warning: ignoring return value of 'CPLErr GDALRasterBand::RasterIO(GDALRWFlag, int, int, int, int, void*, int, int, GDALDataType, GSpacing, GSpacing, GDALRasterIOExtraArg*)' declared with attribute 'warn_unused_result' [-Wunused-result]
39 | poBand->RasterIO(GF_Write, 0, 0, nXSize, nYSize, flatData.data(), nXSize, nYSize, GDT_Float64, 0, 0);
| ~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
test_gdal.cpp: In member function 'double Interpolator2D::interpolate(double, double)':
test_gdal.cpp:48:28: warning: ignoring return value of 'int GDALInvGeoTransform(double*, double*)' declared with attribute 'warn_unused_result' [-Wunused-result]
48 | GDALInvGeoTransform(adfGeoTransform, inv_geotransform);
| ~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
test_gdal.cpp:62:25: warning: ignoring return value of 'CPLErr GDALRasterBand::RasterIO(GDALRWFlag, int, int, int, int, void*, int, int, GDALDataType, GSpacing, GSpacing, GDALRasterIOExtraArg*)' declared with attribute 'warn_unused_result' [-Wunused-result]
62 | poBand->RasterIO(GF_Read, x, y, 2, 2, adfPixel, 2, 2, GDT_Float64, 0, 0);
| ~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/opt/conda/envs/test/bin/../lib/gcc/x86_64-conda-linux-gnu/13.1.0/../../../../x86_64-conda-linux-gnu/bin/ld: /opt/conda/envs/test/lib/libgdal.so: undefined reference to `posix_spawnp@GLIBC_2.15'
/opt/conda/envs/test/bin/../lib/gcc/x86_64-conda-linux-gnu/13.1.0/../../../../x86_64-conda-linux-gnu/bin/ld: /opt/conda/envs/test/lib/libgdal.so: undefined reference to `memcpy@GLIBC_2.14'
collect2: error: ld returned 1 exit status
Try:
$GXX $CXXFLAGS -I$CONDA_PREFIX/include -L$CONDA_PREFIX/lib -lgdal test_gdal.cpp -o test_gdal $LDFLAGS
(CXXFLAGS
doesn't seem strictly needed, but LDFLAGS
definitely does).
Seems to solve the issue, thanks a lot! The option that actually helped to do that is: -Wl,--allow-shlib-undefined
--allow-shlib-undefined Allow unresolved references in shared libraries
Any ideas why this magic is needed to link gdal library compiled by conda-forge on X86? For linux-aarch64 for example it works without. I believe the cross-platform consistency would be appreciated!
I think it is to do with what version of libc
you have installed, but not really my area.
This can be solved by adding
- sysroot_linux-64 2.17 # [linux64]
to the build environment.
Thanks, @h-vetinari ! Indeed, the default sysroot is too outdated to have the symbol.
Solution to issue cannot be found in the documentation.
Issue
Cannot link to libgdal. Any ideas?
Installed packages
Environment info