win10下使用VS2019编译gdal3

1.准备
sqlite3:sqlite3编译
proj6:proj6编译

2.源码下载
https://github.com/OSGeo/GDAL

3.编辑nmake.opt
解压源码包后,打开nmake.opt文件,需要修改几个位置:
1).42行附近
!IFNDEF MSVC_VER
#assume msvc VS2015.
MSVC_VER=1920 #设置编译器
!ENDIF

2).66行附近
!IFNDEF GDAL_HOME
GDAL_HOME = "D:\warmerda\bld" #设置目标位置
!ENDIF

3).128行附近
# Set DEBUG=1 to create a debug build
!IFNDEF DEBUG
DEBUG=1 #设置debug标志,这个可以在编译时参数中再指定
!IFNDEF POSTFIX
POSTFIX=
!ENDIF
!ENDIF

4).136行附近
# Force PDB output for DEBUG mode
!IF "$(DEBUG)" == "1"
WITH_PDB=1 #pdb文件生成
!IFNDEF POSTFIX
POSTFIX=_d
!ENDIF
!ELSE IF "$(DEBUG)" != "0"
!ERROR DEBUG should be set to 0 or 1
!ENDIF

5).156行附近
设置编译选项,一般根据需要设置即可,我采用的静态编译,运行库选择/MT
!IFNDEF OPTFLAGS
!IF "$(DEBUG)" == "0"
OPTFLAGS= $(CXX_ANALYZE_FLAGS) $(CXX_PDB_FLAGS) /nologo /MP$(CPU_COUNT) /MD /EHsc /Ox /FC /D_CRT_SECURE_NO_DEPRECATE /D_CRT_NONSTDC_NO_DEPRECATE /DNDEBUG
!ELSE
OPTFLAGS= $(CXX_ANALYZE_FLAGS) $(CXX_PDB_FLAGS) /nologo /MP$(CPU_COUNT) /MT /EHsc /FC /D_CRT_SECURE_NO_DEPRECATE /D_CRT_NONSTDC_NO_DEPRECATE /DDEBUG
!ENDIF
!ENDIF # OPTFLAGS

6).210行附近
# 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 #是否使用64位方式,可在编译时设置
# Capture WIN64=1 if specified in NMAKE command line
!IFDEF WIN64
WIN64=YES
!ENDIF

7).238行附近
# Set DLLBUILD=0 to create a static lib instead of a shared lib (.DLL)
!IFNDEF DLLBUILD
DLLBUILD=0 #我采用的静态编译,未使用dll,更据需要设置
!ENDIF

8).259行附近
Proj库的设置
# PROJ stuff (required dependency: PROJ >= 6)
PROJ_INCLUDE = -IC:\OSGeo4W\include
# Note: add shell32.lib is needed starting with PROJ 7.0 in some circumstances
# for static linking. See https://github.com/OSGeo/gdal/issues/2488
# And ole32.lib also since PROJ 7.1 (see https://github.com/OSGeo/gdal/issues/2743)
PROJ_LIBRARY = C:\OSGeo4W\lib\proj_6_3_d.lib shell32.lib ole32.lib

9).649行附近
sqlite库的设置
# SQLite Libraries
SQLITE_INC=-ID:\sqlite\SQLite\SQLite3\SQLite3
SQLITE_LIB=D:\sqlite\SQLite\SQLite3\x64\Debug\SQLite3d.lib

其他选项可以根据需要设置。

4.编译
打开vs2019的X64 Native Tools Command Prompt,cd到源码目录下,执行:
nmake -f makefile.vc
或者,如果一些选项未设置,可以在此时设置:
nmake -f makefile.vc MSVC_VER=1920 WIN64=1 DEBUG=1 ANALYZE=1 WITH_PDB=1
完成后执行安装命令,安装到设置的目录中:
nmake -f makefile.vs devinstall
补充一个nmake的清理命令:
nmake -f makefile.vs clean

posted @ 2021-06-04 10:07  soso101  阅读(1075)  评论(0编辑  收藏  举报