OSGeo / gdal

GDAL is an open source MIT licensed translator library for raster and vector geospatial data formats.
https://gdal.org
Other
4.91k stars 2.55k forks source link

$(JPEG12_FLAGS) ignored when compiling with external libjpeg on windows #1014

Closed christapley closed 6 years ago

christapley commented 6 years ago

In master/gdal/frmts/jpeg/makefile.vc

!IFDEF JPEG_EXTERNAL_LIB
EXTRAFLAGS      = -I$(JPEGDIR) -I..\mem
!ELSE
EXTRAFLAGS =    -Ilibjpeg $(JPEG12_FLAGS) -I..\mem
!ENDIF

Could this please be:

!IFDEF JPEG_EXTERNAL_LIB
EXTRAFLAGS      = -I$(JPEGDIR) $(JPEG12_FLAGS) -I..\mem
!ELSE
EXTRAFLAGS =    -Ilibjpeg $(JPEG12_FLAGS) -I..\mem
!ENDIF

So that when building gdal with an external jpeg library on windows frmts/jpeg/*_12.cpp files will be built with JPEG_DUAL_MODE_8_12 defined. I believe this is the same problem Jeff McKenna ran into in Error compiling trunk (nitf) - however, there may have been other problems at runtime as Even Rouault points out.

Without passing these flags, jpgdataset_12.o and vsidataio_12.o will be empty. e.g.:

C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise>dumpbin /SYMBOLS "E:\perforce\Third_Party\gdal\gdal-2.3.0\frmts\o\jpgdataset_12.obj" | find "jpeg_"

C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise>

With the proposed change, we see:

C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise>dumpbin /SYMBOLS "E:\perforce\Third_Party\gdal\gdal-2.3.0\frmts\o\jpgdataset_12.obj" | find "jpeg_vsiio_dest"
17A6 00000000 UNDEF  notype ()    External     | ?jpeg_vsiio_dest_12@@YAXPEAUjpeg_compress_struct12@@PEAU_VSILFILE@@@Z (void __cdecl jpeg_vsiio_dest_12(struct jpeg_compress_struct12 *,struct _VSILFILE *))

C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise>

On linux, the frmts/jpeg/GNUmakefile does not have conditionals around $(JPEG_EXTERNAL_LIB) and always defines -DJPEG_DUAL_MODE_8_12 when jpeg12 is enabled via $(JPEG12_ENABLED).

Steps to reproduce the problem.

  1. Unpack gdal-2.3.0
  2. Configure nmake.opt to use an external jpeg library, but internal jpeg12 library, e.g.
    !IFNDEF JPEG_SUPPORTED
    JPEG_SUPPORTED = 1
    !ENDIF
    JPEG12_SUPPORTED = 1
    JPEG_EXTERNAL_LIB = 1
    JPEG_DIR = $(GDAL_ROOT)\root\$(CPU_ARCH)\jpegturbo\8bit
    JPEGDIR = $(JPEG_DIR)\include
    JPEG_LIB = $(JPEG_DIR)\lib\$(CONF)\turbojpeg-static.lib
  3. build and you should get
     [exec]     link /nologo /dll /INCLUDE:OSRValidate  /INCLUDE:OPTGetProjectionMethods  /INCLUDE:OGR_G_GetPointCount  /INCLUDE:OGRRegisterAll /INCLUDE:GDALSimpleImageWarp  /INCLUDE:GDALReprojectImage  /INCLUDE:GDALComputeMedianCutPCT  /INCLUDE:GDALDitherRGB2PCT  /INCLUDE:OCTNewCoordinateTransformation port\*.obj gcore\*.obj alg\*.obj frmts\o\*.obj ogr\ogrsf_frmts\ogrsf_frmts.lib ogr\ogr.lib gnm\*.obj gnm\gnm_frmts\o\*.obj apps\commonutils.obj apps\gdalinfo_lib.obj apps\gdal_translate_lib.obj apps\gdalwarp_lib.obj apps\ogr2ogr_lib.obj  apps\gdaldem_lib.obj apps\nearblack_lib.obj apps\gdal_grid_lib.obj apps\gdal_rasterize_lib.obj apps\gdalbuildvrt_lib.obj                .\root\x64\jpegturbo\8bit\lib\Debug\jpeg-static.lib       ./root/x64/sqlite//Debug/sqlite3.lib           ./root/x64/curl/Debug/lib/libcurl_a_debug.lib    legacy_stdio_definitions.lib odbc32.lib odbccp32.lib user32.lib                          ws2_32.lib  kernel32.lib psapi.lib gcore\Version.res  /out:gdal203.dll /implib:gdal_i.lib   /debug
     [exec]    Creating library gdal_i.lib and object gdal_i.exp
     [exec] LINK : warning LNK4098: defaultlib 'LIBCMTD' conflicts with use of other libs; use /NODEFAULTLIB:library
     [exec] nitfwritejpeg_12.obj : error LNK2019: unresolved external symbol "void __cdecl jpeg_vsiio_dest_12(struct jpeg_compress_struct12 *,struct _VSILFILE *)" (?jpeg_vsiio_dest_12@@YAXPEAUjpeg_compress_struct12@@PEAU_VSILFILE@@@Z) referenced in function "int __cdecl NITFWriteJPEGBlock_12(class GDALDataset *,struct _VSILFILE *,int,int,int,int,int,int,unsigned char const *,int,int (__cdecl*)(double,char const *,void *),void *)" (?NITFWriteJPEGBlock_12@@YAHPEAVGDALDataset@@PEAU_VSILFILE@@HHHHHHPEBEHP6AHNPEBDPEAX@Z4@Z)
     [exec] gdal203.dll : fatal error LNK1120: 1 unresolved externals
     [exec] NMAKE : fatal error U1077: '"C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\VC\Tools\MSVC\14.14.26428\bin\HostX64\x64\link.EXE"' : return code '0x460'

Operating system

Any windows builds

GDAL version and provenance

2.1.2 and 2.3.0 definitely have this problem, and it is still this way in master.

christapley commented 6 years ago

https://github.com/OSGeo/gdal/commit/e0a37354fb4aa4d63e0a0305958310883b33c8dd