[gdal-dev] Re: GDAL 1.7.2 Windows compilation JAVA JNI doesn't work

Zdeněk Vráblík zdenek at vrablik.org
Wed Aug 4 13:28:13 EDT 2010


Hi,

I have compiled the gdal 1.7.2 for 32 bit windows and tested in
Windows XP. This works fine.

Than my colleague  tested the 64bit dll files with 64 bit Windows 7
and it was working too.

Regards,
Zdenek

On Wed, Aug 4, 2010 at 5:07 PM, Zdeněk Vráblík <zdenek at vrablik.org> wrote:
> Hi all,
>
> I have problem to use java jni generated dll files. I have available
> precompiled dll files with internal formats + MrSID and ECW. These dll
> works fine including JNI.
> Now I have compiled gdal myself, because I need add more formats (GPX,
> GML, KML ) and later possibly SDE.
>
> I can't load the  gdaljni.dll into java.
> I am getting this error:
> Native library load failed.
> java.lang.UnsatisfiedLinkError:
> C:\ZdenekTC\lib\native\GDAL_DATA\gdaljni.dll: The operating system
> cannot run %1
>
> Building env: Windows XP, Microsoft Windows SDK 7.0; Visual Studio
> 2005, gdal 1.7.2; crosscompiler
> Running env: Windows 2003 SP2, sun JDK 6, Tomcat 6, gdal 1.7.2
>
> I am sure I have PE+ dll files. (tested with msys file command)
>
> I tried compile HelloWorld from Java JNI tutorial and I have got same issue.
> rem original cl -IC:\Java1.6\include -IC:\Java1.6\include\win32 /O1
> /Op /Zi /MD /D _STATIC_CPPLIB /Wp64 /W3 /DNDEBUG /DWIN32 /DIAL
> /D_LITTLE_ENDIAN /D_AMD64_ /Damd64 /DWIN32_LEAN_AND_MEAN /c *.c
> cl -IC:\Java1.6\include -IC:\Java1.6\include\win32 /O1 /Op /Zi /MT /D
> _STATIC_CPPLIB /Wp64 /W3 /DNDEBUG /DWIN32 /DIAL /D_LITTLE_ENDIAN
> /D_AMD64_ /Damd64 /DWIN32_LEAN_AND_MEAN /DJNI_IMPLEMENTATION /c *.c
> rem original link /dll /opt:REF /incremental:no /debug /out:HelloWorld.dll *.obj
> link /verbose /dll /opt:REF /incremental:no /out:HelloWorld.dll *.obj
>
> The HelloWorld dll works fine without the MD flag.
> Removing MD parameter doesn't work in gdal JNI dll files.
>
> Do I have to add there any parameter to get gdal jni binding compilled
> correctly?
>
> I think the MD parameter is necessary if there is another part of
> application loading same dll files?
>
>
> Here is standard output from compiling (the swig warning messages are
> not included):
>
>        del .\setup.ini
>        echo "C:\GDAL\gdal1.7.1Win32Win64\win64\gdal172Dist" > .\setup.ini
>        findstr /c:"define GDAL_RELEASE_NAME " ..\gcore\gdal_version.h  >> .\setup.ini
>        cd java
>        if not exist org\gdal\gdal mkdir org\gdal\gdal
>        cd gdal
>        swig.exe -java -c++ -package org.gdal.gdal -outdir ../org/gdal/gdal
> -I../../include/java -o gdal_wrap.cpp ../../../include/gdal.i
>        cd ..
>        cd org\gdal
>        if not exist ogr mkdir ogr
>        cd ../../
>        cd ogr
>        swig.exe -java -c++ -package org.gdal.ogr -outdir ../org/gdal/ogr
> -I../../include/java -o ogr_wrap.cpp ../../../include/ogr.i
>        cd ..
>        cd org\gdal
>        if not exist osr mkdir osr
>        cd ../../
>        cd osr
>        swig.exe -java -c++ -package org.gdal.osr -outdir ../org/gdal/osr
> -I../../include/java -o osr_wrap.cpp ../../../include/osr.i
>        cd ..
>        cd org\gdal
>        if not exist gdalconst mkdir gdalconst
>        cd ../../
>        cd const
>        swig.exe -java -c++ -package org.gdal.gdalconst -outdir
> ../org/gdal/gdalconst -I../../include/java -o gdalconst_wrap.cpp
> ../../../include/gdalconst.i
>        cd ..
>        nmake /nologo /f makefile.vc
>        cd ogr
>        nmake /nologo /f makefile.vc
>        cl /nologo /MT /EHsc /GR /Ox /W3 /DNDEBUG -I..\..\..\port
> -I..\..\..\ogr -I..\..\..\gcore  -I..\..\..\alg
> -I..\..\..\ogr\ogrsf_frmts  -DOGR_ENABLED  -IC:\Java1.5\include
> -IC:\Java1.5\include\win32 /c ogr_wrap.cpp
> ogr_wrap.cpp
>        xcopy /D  /Y *.obj ..
> C:ogr_wrap.obj
> 1 File(s) copied
>        cd ..
>        link ogr_wrap.obj ..\..\gdal_i.lib /out:ogrjni.dll /DLL
> Microsoft (R) Incremental Linker Version 8.00.50727.762
> Copyright (C) Microsoft Corporation.  All rights reserved.
>
>   Creating library ogrjni.lib and object ogrjni.exp
>        if exist ogrjni.dll.manifest mt -manifest ogrjni.dll.manifest
> -outputresource:ogrjni.dll;2
> Microsoft (R) Manifest Tool version 5.2.3790.2075
>
> Copyright (c) Microsoft Corporation 2005.
>
> All rights reserved.
>
>        cd gdal
>        nmake /nologo /f makefile.vc
>        cl /nologo /MT /EHsc /GR /Ox /W3 /DNDEBUG -I..\..\..\port
> -I..\..\..\ogr -I..\..\..\gcore  -I..\..\..\alg
> -I..\..\..\ogr\ogrsf_frmts  -DOGR_ENABLED  -IC:\Java1.5\include
> -IC:\Java1.5\include\win32 /c gdal_wrap.cpp
> gdal_wrap.cpp
> gdal_wrap.cpp(989) : warning C4996: 'stricmp': The POSIX name for this
> item is deprecated. Instead, use the ISO C++ conformant name:
> _stricmp. See online help for details.
>        C:\Program Files\Microsoft Visual Studio
> 8\VC\INCLUDE\string.h(215) : see declaration of 'stricmp'
> gdal_wrap.cpp(991) : warning C4996: 'stricmp': The POSIX name for this
> item is deprecated. Instead, use the ISO C++ conformant name:
> _stricmp. See online help for details.
>        C:\Program Files\Microsoft Visual Studio
> 8\VC\INCLUDE\string.h(215) : see declaration of 'stricmp'
> gdal_wrap.cpp(993) : warning C4996: 'stricmp': The POSIX name for this
> item is deprecated. Instead, use the ISO C++ conformant name:
> _stricmp. See online help for details.
>        C:\Program Files\Microsoft Visual Studio
> 8\VC\INCLUDE\string.h(215) : see declaration of 'stricmp'
> gdal_wrap.cpp(1019) : warning C4267: 'argument' : conversion from
> 'size_t' to 'int', possible loss of data
>        xcopy /D  /Y *.obj ..
> C:gdal_wrap.obj
> 1 File(s) copied
>        cd ..
>        link gdal_wrap.obj ..\..\gdal_i.lib /out:gdaljni.dll /DLL
> Microsoft (R) Incremental Linker Version 8.00.50727.762
> Copyright (C) Microsoft Corporation.  All rights reserved.
>
>   Creating library gdaljni.lib and object gdaljni.exp
>        if exist gdaljni.dll.manifest mt -manifest gdaljni.dll.manifest
> -outputresource:gdaljni.dll;2
> Microsoft (R) Manifest Tool version 5.2.3790.2075
>
> Copyright (c) Microsoft Corporation 2005.
>
> All rights reserved.
>
>        cd const
>        nmake /nologo /f makefile.vc
>        cl /nologo /MT /EHsc /GR /Ox /W3 /DNDEBUG -I..\..\..\port
> -I..\..\..\ogr -I..\..\..\gcore  -I..\..\..\alg
> -I..\..\..\ogr\ogrsf_frmts  -DOGR_ENABLED  -IC:\Java1.5\include
> -IC:\Java1.5\include\win32 /c gdalconst_wrap.cpp
> gdalconst_wrap.cpp
>        xcopy /D  /Y *.obj ..
> C:gdalconst_wrap.obj
> 1 File(s) copied
>        cd ..
>        link gdalconst_wrap.obj ..\..\gdal_i.lib /out:gdalconstjni.dll /DLL
> Microsoft (R) Incremental Linker Version 8.00.50727.762
> Copyright (C) Microsoft Corporation.  All rights reserved.
>
>   Creating library gdalconstjni.lib and object gdalconstjni.exp
>        if exist gdalconstjni.dll.manifest mt -manifest
> gdalconstjni.dll.manifest -outputresource:gdalconstjni.dll;2
> Microsoft (R) Manifest Tool version 5.2.3790.2075
>
> Copyright (c) Microsoft Corporation 2005.
>
> All rights reserved.
>
>        cd osr
>        nmake /nologo /f makefile.vc
>        cl /nologo /MT /EHsc /GR /Ox /W3 /DNDEBUG -I..\..\..\port
> -I..\..\..\ogr -I..\..\..\gcore  -I..\..\..\alg
> -I..\..\..\ogr\ogrsf_frmts  -DOGR_ENABLED  -IC:\Java1.5\include
> -IC:\Java1.5\include\win32 /c osr_wrap.cpp
> osr_wrap.cpp
>        xcopy /D  /Y *.obj ..
> C:osr_wrap.obj
> 1 File(s) copied
>        cd ..
>        link osr_wrap.obj ..\..\gdal_i.lib /out:osrjni.dll /DLL
> Microsoft (R) Incremental Linker Version 8.00.50727.762
> Copyright (C) Microsoft Corporation.  All rights reserved.
>
>   Creating library osrjni.lib and object osrjni.exp
>        if exist osrjni.dll.manifest mt -manifest osrjni.dll.manifest
> -outputresource:osrjni.dll;2
> Microsoft (R) Manifest Tool version 5.2.3790.2075
>
> Copyright (c) Microsoft Corporation 2005.
>
> All rights reserved.
>
>        set JAVA_HOME="C:\Java1.5"
>        C:\ant\bin\ant
> Buildfile: build.xml
>
> compile:
>    [javac] Compiling 34 source files to
> C:\GDAL\gdal1.7.1Win32Win64\win64\gdal-1.7.2\swig\java\build\classes
>     [echo] compilation complete
>
> archive:
>      [jar] Building jar:
> C:\GDAL\gdal1.7.1Win32Win64\win64\gdal-1.7.2\swig\java\gdal.jar
>
> compile_tests:
>     [echo] compilation of tests complete
>
> all:
>
> BUILD SUCCESSFUL
> Total time: 1 second
>
>
> nmake.opt diff is
> --- nmake.opt.original  2010-04-23 16:22:12 +0100
> +++ nmake.opt   2010-08-04 16:21:14 +0100
> @@ -39,7 +39,7 @@
>  # But the paths *should* be absolute (relative paths mess up in submakefiles).
>
>  !IFNDEF GDAL_HOME
> -GDAL_HOME = "C:\warmerda\bld"
> +GDAL_HOME = "C:\GDAL\gdal1.7.1Win32Win64\win64\gdal172Dist"
>  !ENDIF
>  BINDIR = $(GDAL_HOME)\bin
>  PLUGINDIR = $(BINDIR)\gdalplugins
> @@ -61,10 +61,10 @@
>
>  # SWIG Java settings
>  !IFNDEF JAVA_HOME
> -JAVA_HOME = c:\j2sdk1.4.2_12
> +JAVA_HOME = C:\Java1.6
>  !ENDIF
>  !IFNDEF ANT_HOME
> -ANT_HOME=c:\programmi\apache-ant-1.7.0
> +ANT_HOME=C:\ant
>  !ENDIF
>  JAVADOC=$(JAVA_HOME)\bin\javadoc
>  JAVAC=$(JAVA_HOME)\bin\javac
> @@ -76,15 +76,15 @@
>  !IFNDEF OPTFLAGS
>  !IF $(MSVC_VER) >= 1400
>  !IFNDEF DEBUG
> -OPTFLAGS= /nologo /MD /EHsc /Ox /W3 /D_CRT_SECURE_NO_DEPRECATE
> /D_CRT_NONSTDC_NO_DEPRECATE /DNDEBUG
> +OPTFLAGS= /nologo /MT /EHsc /Ox /W3 /D_CRT_SECURE_NO_DEPRECATE
> /D_CRT_NONSTDC_NO_DEPRECATE /DNDEBUG
>  !ELSE
> -OPTFLAGS= /nologo /MD /EHsc /Zi /W4 /D_CRT_SECURE_NO_DEPRECATE
> /D_CRT_NONSTDC_NO_DEPRECATE /Fd$(GDAL_ROOT)\gdal$(VERSION).pdb
> +OPTFLAGS= /nologo /MT /EHsc /Zi /W4 /D_CRT_SECURE_NO_DEPRECATE
> /D_CRT_NONSTDC_NO_DEPRECATE /Fd$(GDAL_ROOT)\gdal$(VERSION).pdb
>  !ENDIF
>  !ELSE
>  !IFNDEF DEBUG
> -OPTFLAGS=      /nologo /MD /EHsc /GR /Ox /W3 /DNDEBUG
> +OPTFLAGS=      /nologo /MT /EHsc /GR /Ox /W3 /DNDEBUG
>  !ELSE
> -OPTFLAGS=      /nologo /MD /EHsc /GR /Zi /W4 /Fd$(GDAL_ROOT)\gdal$(VERSION).pdb
> +OPTFLAGS=      /nologo /MT /EHsc /GR /Zi /W4 /Fd$(GDAL_ROOT)\gdal$(VERSION).pdb
>  !ENDIF
>  !ENDIF  #MSVC_VER
>  !ENDIF  # OPTFLAGS
> @@ -97,7 +97,7 @@
>  # Uncomment the following if you are building for 64-bit windows
>  # (x64). You'll need to have PATH, INCLUDE and LIB set up for 64-bit
>  # compiles.
> -#WIN64=YES
> +WIN64=YES
>
>  # If you don't want some entry points to have STDCALL conventions,
>  # comment out the following and add -DCPL_DISABLE_STDCALL in OPTFLAGS.
> @@ -160,9 +160,10 @@
>  #GEOTIFF_LIB =   C:/warmerda/libgeotiff/geotiff_i.lib
>
>  # Uncomment the following and update to enable ECW support.
> -#ECW_PLUGIN = NO
> -#ECWDIR  =     C:\warmerda\libecwj2-3.3
> -#ECWLIB  =     $(ECWDIR)\Source\NCSBuildQmake\Debug\libecwj2.lib
> +ECW_PLUGIN = YES
> +ECWDIR=C:\GDAL\gdal1.7.1Win32Win64\win64\libecwj2-3.3
> +#ECWLIB=$(ECWDIR)\lib\win64\*.lib
> +ECWLIB=$(ECWDIR)\lib\win64\NCSEcw.lib
> $(ECWDIR)\lib\win64\NCSEcwCu.lib $(ECWDIR)\lib\win64\NCSUtil.lib
> $(ECWDIR)\lib\win64\NCScnet.lib $(ECWDIR)\lib\win64\NCSEcwC.lib
> $(ECWDIR)\lib\win64\NCSEcwS.lib $(ECWDIR)\lib\win64\NCSUtilS.lib
> $(ECWDIR)\lib\win64\NCScnetS.lib
>
>  # DWG/DXF support via DWGdirect from Open Design Alliance
>
> @@ -177,9 +178,9 @@
>  #              $(OGDIDIR)\lib\$(TARGET)\zlib_ogdi$(OGDIVER).lib
>
>  # Uncomment for Expat support (required for KML, GPX and GeoRSS read support).
> -#EXPAT_DIR = "C:\Program Files\Expat 2.0.1"
> -#EXPAT_INCLUDE = -I$(EXPAT_DIR)/source/lib
> -#EXPAT_LIB = $(EXPAT_DIR)/bin/libexpat.lib
> +EXPAT_DIR = C:\GDAL\gdal1.7.1Win32Win64\win64\expat-2.0.1\win32\bin\release
> +EXPAT_INCLUDE = -IC:\GDAL\gdal1.7.1Win32Win64\win64\expat-2.0.1\lib
> +EXPAT_LIB = C:\GDAL\gdal1.7.1Win32Win64\win64\expat-2.0.1\win32\bin\release\libexpatMT.lib
>
>  # Uncomment for Xerces based GML and ILI support.
>  #XERCES_DIR =  c:\warmerda\supportlibs\xerces-c_2_6_0
> @@ -219,12 +220,12 @@
>
>  # Uncomment the following for MrSID support.
>  # You will likely require /MD and /EHsc in OPTFLAGS.
> -#MRSID_DIR =   d:\projects\mrsid
> -#MRSID_INCLUDE = -I$(MRSID_DIR)\include\base -I$(MRSID_DIR)\include\support \
> -#              -I$(MRSID_DIR)\include\metadata \
> -#              -I$(MRSID_DIR)\include\mrsid_readers \
> -#              -I$(MRSID_DIR)\include\j2k_readers
> -#MRSID_LIB =   $(MRSID_DIR)\lib\Release_md\lti_dsdk_dll.lib
> advapi32.lib user32.lib
> +MRSID_DIR =    C:\GDAL\gdal1.7.1Win32Win64\win64\Geo_DSDK-7.0.0.2167
> +MRSID_INCLUDE = -I$(MRSID_DIR)\include\base -I$(MRSID_DIR)\include \
> +               -I$(MRSID_DIR)\include\metadata \
> +               -I$(MRSID_DIR)\include\mrsid_readers \
> +               -I$(MRSID_DIR)\include\j2k_readers
> +MRSID_LIB =    $(MRSID_DIR)\lib\Release_md\lti_dsdk_dll.lib advapi32.lib
> user32.lib
>  # Comment out the following to supress JP2MRSID driver.
>  #MRSID_FLAGS = -DMRSID_J2K
>  # Enable these, if you have the MrSID Encoding SDK and want
> @@ -234,7 +235,7 @@
>  #              -I$(MRSID_DIR)\include\j2k_writers $(MRSID_INCLUDE)
>  #MRSID_LIB =   $(MRSID_DIR)\lib\Release_md\lti_esdk_dll.lib $(MRSID_LIB)
>  # Enable the following if you prefer to build MrSID support as a plugin.
> -#MRSID_PLUGIN = YES
> +MRSID_PLUGIN = YES
>
>  # PCIDSK Libraries - default configuration uses internal implementation
>  PCIDSK_SETTING=INTERNAL
>
>
> Do I have to add any new parameters to compile jni dll files? Did I
> any wrong step during compilation?
>
> I could send you full description what I have done to compile ecw and
> installing the Windows SDK if required.
> I have compiled gdal 1.7.1 in linux 64bit and Solaris SPARC 64 bit and
> it works fine.
>
> I have tested the compiled dll files in two different runtime environments.
>
> Thank you for your help.
>
> Regards,
> Zdenek
>


More information about the gdal-dev mailing list