ddk开发 c语言,使用DDK提供的build进行编译驱动一点总结

DDK通过调用build工具进行编译以及链接代码,而build又是通过传递一些编译的参数调用nmake工具进行解析makefile文件(其中,makefile文件中指定了需要编译的文件的依赖关系,指定的过程是有顺序的,要指明先编译哪些文件,后编译哪些文件;不管是build,还是nmake,甚至是VC,它们最终调用的都是cl.exe和link.exe),传参很多,可以自己查询文档;这里边makefile需要列出一系列的依赖关系,从头写makefile会很烦人,大多数情况下我们只需要写一行:

! INCLUDE $(MAKEENVNT) \makefile.def,想要深入了解去MSDN上看一下,我之后有时间或者遇到这方面的需要的时候再深入看了。

有了自定义的编译依赖关系或者使用默认的makefile之后,得告诉build编译哪些文件,这些文件的路径在哪,这就遇到了source和 dirs文件。source里边记录了需要编译的源文件文件名、包含目录路径、库目录路径等,有了目标才能进行编译是吧?而具体设置自己查询文档,继续说整体流程;多数项目不可能仅仅用了一个文件夹,这就遇到了需要编译的文件放在不同位置,也就有了dirs文件,这个里边描述了需要编译的子目录路径,这样build会依次进入dirs里边写的子目录寻找source进而将所有需要编译的文件都编译,生成需要的静态库*.lib等等。

整体流程说完了,具体说一下:

001:生成静态库的准备:

先设置makefile为默认的那一行,之后编写dirs和source文件

dirs很简单,比如:

DIRS=\

filepath1\

filepath2\

filepath3\

filepath4\

filepath5\

右边的'\'出现在结尾,表示下一行与本行是一行,只不过分行写,看着清晰

然后具体说一下source:

TARGETNAME:目标驱动的名称

TARGETTYPE:目标代码生成类型,写成DRIVER表示驱动,PROGRAM表示编译成Win32程序

TARGETPATH:目标代码生成的路径

C_DEFINES :相当于C语言中的#define,不过这里边比如宏定义MY_TYPE,需要前边加一个"-D",比如这样:C_DEFINES = -DMY_TYPE1  -DMY_TYPE2

TARGETLIBS:设置代码所需要的库

SOURCES:指定此工程需要的所有源文件,只指定C和C++文件,不需要头文件,比如:

SOURCES=a.c\

b.c++\

c.c\

注意前边是TAB不是空格,否则不识别,报错

002:设置编译环境,平台等:

使用的的是DDK里边setenv.bat , 一般这样调用:

call %DDKROOT%\bin\setenv.bat  %DDKROOT%  %1 %2 %3

其中,DDKROOT是环境变量,一般为:C:\WinDDK\600

%1是编译方式,chk或者fre,分别对应VC编译中我们熟悉的debug和release版本

%2是处理器,一般为x86、x64、ia64、AMD64

%3是操作系统,一般有:WXP , WIN7 , WLH

call 了setenv.bat之后就可以编译了:

build /c /w /g

/c 表示只进行编译,不进行链接

/w 表示采用第三集警报模式

/g 表示默认函数采用标准调用(__stdcall)

这样就编译出来了想要的静态库*.lib了。

003:

生成驱动:

将编译好的静态库拷贝到最终编译生成驱动的设置的静态文件的目录下,之后使用命令:

build  -b  -w  WXP -nmake  /a

这行批处理所在的目录为source目录下,最终就生成了需要的编译结果:目标驱动,具体细节我也在学习中,初学者,肯定会有理解不到位的地方,希望发现问题的朋友不吝提醒,谢谢。

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
DDKWizard is a so-called project creation wizard that allows you to create projects that use the DDKBUILD scripts from OSR (also available in the download section from this site). The wizard will give you several options to configure your project prior to the creation. Have a look at figure 1. Figure 2: Project creation dialog (click to enlarge) Instead of forcing you to use a subset of options and specific DDKs this wizard lets you choose what you want. Of course the template files are predefined and so is the content of the project(s) within certain limits. However, I tried to choose the best options that I could think of and provide a way to create quickly and easily the DDKBUILD project you want. This means that I tried to leave out those things that may limit your choice lateron and add other options that will give you the flexibility to change options quickly long after the project was created. DDKWizard adds a new subfolder in the project creation wizard - see figure 2 - and presents all supported project types there. Currently these are Driver, Empty Driver, Native Application, Win32 console application and Win32 DLL. In either case you just choose the type of project to create, give the name of the project and/or solution as well as other options (at the bottom) and you are being presented the wizard dialog (see figure 1). From the wizard dialog you choose the DDKBUILD script you want to use, the DDK or multiple DDKs as well as the other options. If you are curious about the Property Sheet feature, please download the manual and read the respective section there. Compatibility DDKWizard (1.2.0a) has been tested on the following configurations: Visual Studio Professional .NET with WNET DDK and DDKBUILD.CMD on Windows 2003 Server R2 Standard Visual Studio Professional .NET 2003 with WNET DDK and DDKBUILD.CMD on Windows 2003 Server R2 Standard Visual C++ 2005 Express with WNET DDK and DDKBUILD.CMD on Windows 2003 Server R2 Standard Visual Studio 2005 Professional with WNET DDK and DDKBUILD.CMD on Windows 2003 Server R2 Standard Visual Studio 2008 Professional with WNET DDK and DDKBUILD.CMD on Windows XP From this list one can deduce that it is supposed to also run if you got the respective "non-Express" Visual C++ version. Also if there has been some Visual C++ .NET 2003 Express DDKWizard is prepared for it. Download You could go watch the demo or download right away: Manual: contains the detailed description of how to configure DDKBUILD and use DDKWizard. If you are unsure whether you should download and install DDKWizard grab this file and skim over it. Download: ddkwiz_manual.pdf (~513kB, 2009-12-05@20-11-55, downloaded 31666 times) Installer (incl. manual) of DDKWizard 1.3.0a: this is the setup program which will install DDKWizard along with the manual on your computer and register it with Visual Studio. Download: ddkwizard_setup.exe (~557kB, 2009-12-05@20-12-37, downloaded 72787 times) DDKBUILD.CMD: Stable version 7.4/r60 of OSRs DDKBUILD NT script version. Feedback for this version can be sent to me directly. Download: ddkbuild_cmd.zip (~12kB, 2009-11-28@04-38-36, downloaded 20707 times) DDKBUILD.BAT (obsoleted by the above!): Version 6.12 of OSRs DDKBUILD batch script version. Download: ddkbuild_bat.zip (~6kB, 2008-03-21@15-59-07, downloaded 17226 times) Trunk version of DDKBUILD.CMD The version from trunk is available as well. Please note that this is not necessarily the same version as offered in the ZIP archive above. It may be in a better shape (e.g. reported bugs fixed) or slightly worse (e.g. new feature that is not yet stable). So use this version only if you want to test the latest development version and are able to provide feedback. Here is the link to the prettier ViewVC URL: ddkbuild/trunk - SVN clients get read-only access here. License All projects created by DDKWizard can be put under whatever license you like to put them. The scripts and HTML files which contain the DDKWizard logic are subject to the zlib license starting with version 1.2.0, before it was released under the GPL v2 from 1991. The zlib license is a lot more liberal and allows just about any kind of use for the script and "user interface" part of DDKWizard. The DDKBUILD scripts are mirrored with the permission of OSR. I will try to keep it synchronized at all times. Everything else Contact me here and also visit my blog and my website. Note that I usually announce new versions of DDKWizard and DDKBUILD on my blog - you also might want to subscribe to the RSS feed for DDKWizard and DDKBUILD. This page will be extended whenever I deem it necessary.

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值