OSGeo / libgeotiff

Official repository of the libgeotiff project
180 stars 69 forks source link

Configure script not finding dependencies as static libraries #32

Closed jeroen closed 4 years ago

jeroen commented 4 years ago

I'm building libgeotiff in an environment with only static libraries. Therefore, libproj needs to be linked with -lproj -lsqlite3 and libtiff needs to be linked as follows:

pkg-config --libs-only-l --static libtiff-4
#  -ltiff -ljpeg -lz

When I run ./configure --enable-static --disable-shared --with-proj it errors like so:

checking for PROJ >= 6 library... checking for proj_create_from_wkt in -lproj... no
checking for internal_proj_create_from_wkt in -lproj... no
checking for internal_proj_create_from_wkt in -linternalproj... no
configure: error: PROJ 6 symbols not found

From configure.log I see the configure test fails because:

I was able to work around it like so:

export LIBS="-lsqlite3 -lstdc++"
./configure --enable-static --disable-shared --with-proj

How the configure script succeeds, and I am able to build libgeotiff.a however the build fails when it needs to link to libtiff:

libtool: link: x86_64-w64-mingw32-gcc -I../../libgeotiff-1.5.1 -I../../libgeotiff-1.5.1/libxtiff -DHAVE_TIFF=1 -march=x86-64 -mtune=generic -O2 -pipe -O3 -DNDEBUG -pipe -o applygeo.exe applygeo.o -pipe  ../.libs/libgeotiff.a -lproj -lsqlite3 -ljpeg -lz -lstdc++ -ltiff
C:/msys64/mingw64/lib/gcc/x86_64-w64-mingw32/8.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/msys64/mingw64/lib/gcc/x86_64-w64-mingw32/8.3.0/../../../../lib/libtiff.a(tif_jpeg.o):(.text+0x244): undefined reference to `jpeg_std_error'
C:/msys64/mingw64/lib/gcc/x86_64-w64-mingw32/8.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/msys64/mingw64/lib/gcc/x86_64-w64-mingw32/8.3.0/../../../../lib/libtiff.a(tif_jpeg.o):(.text+0x2a3): undefined reference to `jpeg_CreateDecompress'
C:/msys64/mingw64/lib/gcc/x86_64-w64-mingw32/8.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/msys64/mingw64/lib/gcc/x86_64-w64-mingw32/8.3.0/../../../../lib/libtiff.a(tif_jpeg.o):(.text+0x375): undefined reference to `jpeg_abort'
... + 100+ more like this

The problem is that it need to link to libtiff using -ltiff -ljpeg -lz instead of -ltiff. However I cannot work around these by adding them to LIBS because it seems the configure script is explicitly stripping -ltiff from LIBS and then putting it back at the end (but -ljpeg and -lz need to appear after -ltiff in the linker flags)

I was able to work around it like so:

sed -i.bak "s/-ltiff/$(pkg-config --libs-only-l --static libtiff-4)/g" configure

Then it builds 🎉 But it's all a bit hacky of course. The configure script could be improved by:

Thanks! Not super urgent (I have workarounds).