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