用WDK命令行CMD编译一个驱动程序时,关于环境变量的记录
扫描二维码
随时随地手机看文章
当使用WDK(我这里版本WDK 7600.16385.1)命令行编译一个驱动程序时,进入到当前驱动所在的文件夹目录下,一般都有一个Sources文件,内容一般是:
TARGETNAME=UsbKbd TARGETTYPE=DRIVER DRIVERTYPE=WDM TARGETPATH=OBJ #TARGETLIBS=C:98DDKLIBI386FREEUsbd.Lib TARGETLIBS=$(DDK_LIB_PATH)Usbd.Lib INCLUDES=$(BASEDIR)inc; SOURCES= Init.cpp Dispatch.cpp Pnp.cpp DeviceIo.cpp Usb.cpp DebugPrint.c # UsbKbd.rc NTTARGETFILES=PostBuildSteps
例如上面的Sources例子里(是编译UsbKbd驱动),“#”是注释符,“DDK_LIB_PATH”等环境变量定义在什么地方呢?
开启一个WDK命令行编译环境,执行下面操作:
C:WinDDK7600.16385.1>set >c:1.txt
上面操作的意思是,将当前命令行cmd下所有的环境变量输出到c:1.txt内,打开该文件,如下:
386=1 ALLUSERSPROFILE=C:ProgramData APPDATA=C:UsersAdministratorAppDataRoaming asl.log=Destination=file ATL_INC_PATH=C:WinDDK7600.16385.1inc ATL_INC_ROOT=C:WinDDK7600.16385.1inc ATL_LIB_PATH=C:WinDDK7600.16385.1libatl* BASEDIR=C:WinDDK7600.16385.1 BUILD_ALLOW_COMPILER_WARNINGS=1 BUILD_ALT_DIR=chk_wxp_x86 BUILD_DEFAULT=-ei -nmake -i -nosqm BUILD_DEFAULT_TARGETS=-386 BUILD_MAKE_PROGRAM=nmake.exe BUILD_MULTIPROCESSOR=1 BUILD_OACR=1 COFFBASE_TXT_FILE=C:WinDDK7600.16385.1bincoffbase.txt CommonProgramFiles=C:Program FilesCommon Files CommonProgramFiles(x86)=C:Program Files (x86)Common Files CommonProgramW6432=C:Program FilesCommon Files COMPUTERNAME=XT1-20140726YGA ComSpec=C:Windowssystem32cmd.exe CPU=AMD64 CRT_INC_PATH=C:WinDDK7600.16385.1inccrt CRT_LIB_PATH=C:WinDDK7600.16385.1libcrt* DDKBUILDENV=chk DDK_INC_PATH=C:WinDDK7600.16385.1incddk DDK_LIB_DEST=C:WinDDK7600.16385.1libwxp DDK_LIB_PATH=C:WinDDK7600.16385.1libwxp* DDK_TARGET_OS=WinXP DEPRECATE_DDK_FUNCTIONS=1 DEVMGR_SHOW_DETAILS=1 DRIVER_INC_PATH=C:WinDDK7600.16385.1incddk FP_NO_HOST_CHECK=NO HALKIT_INC_PATH=C:WinDDK7600.16385.1incddk HALKIT_LIB_PATH=C:WinDDK7600.16385.1libwxp* HOMEDRIVE=C: HOMEPATH=UsersAdministrator IFSKIT_INC_PATH=C:WinDDK7600.16385.1incddk IFSKIT_LIB_DEST=C:WinDDK7600.16385.1libwxp IFSKIT_LIB_PATH=C:WinDDK7600.16385.1libwxp* Include=C:WinDDK7600.16385.1incapi KMDF_INC_PATH=C:WinDDK7600.16385.1incwdfkmdf KMDF_LIB_PATH=C:WinDDK7600.16385.1libwdfkmdf* LANGUAGE_NEUTRAL=0 Lib=C:WinDDK7600.16385.1lib LINK_LIB_IGNORE=4198 LOCALAPPDATA=C:UsersAdministratorAppDataLocal LOGONSERVER=\XT1-20140726YGA MFC_INC_PATH=C:WinDDK7600.16385.1incmfc42 MFC_LIB_PATH=C:WinDDK7600.16385.1libmfc* MSC_OPTIMIZATION=/Od /Oi NEW_CRTS=1 NO_BINPLACE=TRUE NO_BROWSER_FILE=TRUE NTDBGFILES=1 NTDEBUG=ntsd NTDEBUGTYPE=both NTMAKEENV=C:WinDDK7600.16385.1bin NUMBER_OF_PROCESSORS=4 OAK_INC_PATH=C:WinDDK7600.16385.1incapi OS=Windows_NT Path=C:WinDDK7600.16385.1binamd64;C:WinDDK7600.16385.1toolssdvbin;C:WinDDK7600.16385.1binx86oacr;C:WinDDK7600.16385.1toolspfdbinbinx86;C:WinDDK7600.16385.1toolstracingi386;C:WinDDK7600.16385.1binx86;C:WinDDK7600.16385.1binx86x86;C:WinDDK7600.16385.1binSelfSign;C:Windowssystem32;C:Windows;C:WindowsSystem32Wbem;C:WindowsSystem32WindowsPowerShellv1.0;C:Program Files (x86)Windows Kits8.0Windows Performance Toolkit;C:Program FilesMicrosoft SQL Server110ToolsBinn PATHEXT=.COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC PREFAST_VALID_IMPLIES_NOTNULL=1 PROCESSOR_ARCHITECTURE=AMD64 PROCESSOR_IDENTIFIER=Intel64 Family 6 Model 58 Stepping 9, GenuineIntel PROCESSOR_LEVEL=6 PROCESSOR_REVISION=3a09 ProgramData=C:ProgramData ProgramFiles=C:Program Files ProgramFiles(x86)=C:Program Files (x86) ProgramW6432=C:Program Files PROJECT_ROOT=C:WinDDK7600.16385.1src PROMPT=$P$G PSModulePath=C:Windowssystem32WindowsPowerShellv1.0Modules PUBLIC=C:UsersPublic PUBLIC_ROOT=C:WinDDK7600.16385.1 PUBLISH_CMD=@echo Publish not available... RAZZLETOOLPATH=C:WinDDK7600.16385.1Bin RCNOFONTMAP=1 SDK_INC_PATH=C:WinDDK7600.16385.1incapi SDK_LIB_DEST=C:WinDDK7600.16385.1libwxp SDK_LIB_PATH=C:WinDDK7600.16385.1libwxp* SDV=C:WinDDK7600.16385.1toolssdv separate_object_root=FALSE SESSIONNAME=Console SUBSTITUTE_386_CC=C:WinDDK7600.16385.1Binx86oacroacrcl SUBSTITUTE_AMD64_CC=C:WinDDK7600.16385.1Binx86oacroacrcl SUBSTITUTE_CS_COMPILER_NAME=C:WinDDK7600.16385.1BINx86oacroacrcsc /nologo SUBSTITUTE_LINK=C:WinDDK7600.16385.1Binx86oacroacrlink SystemDrive=C: SystemRoot=C:Windows TEMP=C:UsersADMINI~1AppDataLocalTemp TMP=C:UsersADMINI~1AppDataLocalTemp UMDF_INC_PATH=C:WinDDK7600.16385.1incwdfumdf USERDOMAIN=XT1-20140726YGA USERNAME=WinDDK USERPROFILE=C:UsersAdministrator USE_OBJECT_ROOT=1 VBOX_MSI_INSTALL_PATH=C:Program FilesOracleVirtualBox VS110COMNTOOLS=C:Program Files (x86)Microsoft Visual Studio 11.0Common7Tools WDM_INC_PATH=C:WinDDK7600.16385.1incddk windir=C:Windows windows_tracing_flags=3 windows_tracing_logfile=C:BVTBinTestsinstallpackagecsilogfile.log WPP_CONFIG_PATH=C:WinDDK7600.16385.1binwppconfig _BUILDARCH=x86 _BuildType=chk _DFX_INSTALL_UNSIGNED_DRIVER=1 _IA32bit=true _NTDRIVE=C: _NTROOT=WinDDK7600.16385.1 _NT_TARGET_VERSION=0x501 _OACR_ERROR_LEVEL=0 _RunOacr=TRUE
在这里,就能找到“DDK_LIB_PATH”等环境变量定义值了。(如上我开启的是WinXP的Check版本的编译环境)
举一反三:
① 启动一个默认的CMD命令行环境,执行“set >c:1.txt”后,再开启VS2012的命令行提示编译环境,执行“set >c:2.txt”,用文件比较工具比较两个文件的不同。这两个文件的不同,就是VS2012命令行编译环境做的特殊设置。
② 用同样的方式,可以查看WinCE5.0、Tornado2.2命令行编译设置的不同;
② 用同样的方式,查看Visual Studio之间做的设置环境变量区别:VC++6.0的设置环境变量位置一般在“C:Program Files (x86)Microsoft Visual StudioVC98Bin”下,为“VCVARS32.BAT”;VS2005,VS2008,VS2012分别在菜单下有命令行编译提示工具设置;