当前位置:首页 » 编程软件 » 驱动编译命令

驱动编译命令

发布时间: 2023-08-06 06:31:31

㈠ 如何编译一个linux下的驱动模块

这是一个简单而完整的实例,对于理解Linux下的驱动模块是非常有帮助的。

1.源码如下:
/*
* hello.c -- the example of printf "hello world!" in the screen of driver program
*/
#include <linux/init.h>
#include <linux/mole.h>
MODULE_LICENSE("Dual BSD/GPL");/* declare the license of the mole ,it is necessary */
static int hello_init(void)
{
printk(KERN_ALERT "Hello World enter!\n");
return 0;
}
static int hello_exit(void)
{
printk(KERN_ALERT "Hello world exit!\n");
}
mole_init(hello_init); /* load the mole */
mole_exit(hello_exit); /* unload the mole */
进入目录:
[root@Alex_linux /]#cd /work/jiakun_test/moletest
[root@Alex_linux moletest]# vi hello.c
然后拷入上面书上的源码。
2.编译代码:
1>.首先我在2.4内核的虚拟机上进行编译,编译过程如下:
[root@Alex_linux moletest]#gcc -D__KERNEL__ -I /usr/src/linux -DMODULE -Wall -O2 -c -o hello.o hello.c
其中-I选项指定内河源码,也就是内核源码树路径。编译结果:
hello.c:1:22: net/sock.h: No such file or directory
hello.c: In function `hello_init':
hello.c:6: warning: implicit declaration of function `printk'
hello.c:6: `KERN_ALERT' undeclared (first use in this function)
hello.c:6: (Each undeclared identifier is reported only once
hello.c:6: for each function it appears in.)
hello.c:6: parse error before string constant
hello.c: In function `hello_exit':
hello.c:11: `KERN_ALERT' undeclared (first use in this function)
hello.c:11: parse error before string constant
hello.c: At top level:
hello.c:13: warning: type defaults to `int' in declaration of `mole_init'
hello.c:13: warning: parameter names (without types) in function declaration
hello.c:13: warning: data definition has no type or storage class
hello.c:14: warning: type defaults to `int' in declaration of `mole_exit'
hello.c:14: warning: parameter names (without types) in function declaration
hello.c:14: warning: data definition has no type or storage class
在网上查询有网友提示没有引入kernel.h
解决:vi hello.c
在第一行加入:#include <linux/kernel.h>
再次编译仍然报KERN_ALERT没有声明
修改编译条件-I,再次编译:
[root@Alex_linux moletest]#gcc -D__KERNEL__ -I /usr/src/linux -DMODULE -Wall -O2 -c -o hello.o hello.c
[root@Alex_linux moletest]#ls
hello.c hello.o Makefile
[root@Alex_linux moletest]#
2>.接着我尝试在2.6内核的虚拟机上进行编译
编译过程如下:
[root@JiaKun moletest]# ls
hello.c makefile
[root@JiaKun moletest]# vi hello.c
[root@JiaKun moletest]# make
make -C /mylinux/kernel/2.4.18-rmk7 M=/home/alex/test/moletest moles
make: *** /mylinux/kernel/2.4.18-rmk7: No such file or directory. Stop.
make: *** [moles] Error 2
[root@JiaKun moletest]# vi makefile
[root@JiaKun moletest]# make
make -C /usr/src/kernels/2.6.18-53.el5-i686 M=/home/alex/test/moletest moles
make[1]: Entering directory `/usr/src/kernels/2.6.18-53.el5-i686'
scripts/Makefile.build:17: /home/alex/test/moletest/Makefile: No such file or directory
make[2]: *** No rule to make target `/home/alex/test/moletest/Makefile'. Stop.
make[1]: *** [_mole_/home/alex/test/moletest] Error 2
make[1]: Leaving directory `/usr/src/kernels/2.6.18-53.el5-i686'
make: *** [moles] Error 2
[root@JiaKun moletest]# mv makefile Makefile
[root@JiaKun moletest]# make
make -C /usr/src/kernels/2.6.18-53.el5-i686 M=/home/alex/test/moletest moles
make[1]: Entering directory `/usr/src/kernels/2.6.18-53.el5-i686'
CC [M] /home/alex/test/moletest/hello.o
Building moles, stage 2.
MODPOST
CC /home/alex/test/moletest/hello.mod.o
LD [M] /home/alex/test/moletest/hello.ko
make[1]: Leaving directory `/usr/src/kernels/2.6.18-53.el5-i686'
[root@JiaKun moletest]# ls
hello.c hello.ko hello.mod.c hello.mod.o hello.o Makefile Mole.symvers

3.执行代码,加载驱动模块:
2.4内核加载模块:
insmod ./hello.o
但是此时并没有输出printk打印的信息。但是可以在/var/log/messages 中看到打印的信息,这是由于KERN_ALERT优先级不够高。这里
需要修改为:KERN_EMERG。再次编译,加载模块即可以看到结果
2.6内核加载模块:
[root@JiaKun moletest]# insmod hello.ko
[root@JiaKun moletest]#
Message from syslogd@ at Sat Jul 26 19:52:44 2008 ...
JiaKun kernel: Hello, world
有的朋友可能会出现insmod命令找不到的错误,这可能有下面几个原因:
<1> 你的系统没有安装mole-init-tools工具,关于此问题,只需安装即可,但是一般装完系统是有这个命令的。
<2> 环境变量没有添加导致不能使用该命令。使用echo $PATH即可查看PATH环境变量,发现没有/sbin这个路径,所以你当然不能使用insmod这个命令了。解决的方法很简单,只需在命令行输入:
PATH = "$PATH:/sbin"即可添加。(insmod在/sbin这个目录下,你可以使用whereis insmod查看)。
<3> insmod这个命令需要在root权限下才能使用。
加载完成后你可以输入lsmod查看hello这个模块哦。

4.卸载驱动模块:rmmod hello.
加载模块后就可在屏幕上看到如下信息:Hello world enter.
卸载时就可在屏幕上看到如下信息:hello world exit.
[root@JiaKun moletest]# rmmod hello.ko
[root@JiaKun moletest]#
Message from syslogd@ at Sat Jul 26 19:52:58 2008 ...
JiaKun kernel: Goodbye, cruel world

另外,如果有多个文件,则按下列方式编写Makefile文件(file1.c、file2.c):
obj -m := molename.o
mole-objs := file1.o file2.o

㈡ linux怎么编译进驱动进内核

一、 驱动程序编译进内核的步骤
在 linux 内核中增加程序需要完成以下三项工作:
1. 将编写的源代码复制到 Linux 内核源代码的相应目录;
2. 在目录的 Kconfig 文件中增加新源代码对应项目的编译配置选项;
3. 在目录的 Makefile 文件中增加对新源代码的编译条目。

bq27501驱动编译到内核中具体步骤如下:
1. 先将驱动代码bq27501文件夹复制到 ti-davinci/drivers/ 目录下。
确定bq27501驱动模块应在内核源代码树中处于何处。
设备驱动程序存放在内核源码树根目录 drivers/ 的子目录下,在其内部,设备驱动文件进一步按照类别,类型等有序地组织起来。
a. 字符设备存在于 drivers/char/ 目录下
b. 块设备存放在 drivers/block/ 目录下
c. USB 设备则存放在 drivers/usb/ 目录下。
注意:
(1) 此处的文件组织规则并非绝对不变,例如: USB 设备也属于字符设备,也可以存放在 drivers/usb/ 目录下。
(2) 在 drivers/char/ 目录下,在该目录下同时存在大量的 C 源代码文件和许多其他目录。所有对于仅仅只有一两个源文件的设备驱动程序,可以直接存放在该目录下,但如果驱动程序包含许多源文件和其他辅助文件,那么可以创建一个新子目录。
(3) bq27501的驱动是属于字符设备驱动类别,虽然驱动相关的文件只有两个,但是为了方面查看,将相关文件放在了bq27501的文件夹中。在drivers/char/目录下增加新的设备过程比较简单,但是在drivers/下直接添加新的设备稍微复杂点。所以下面首先给出在drivers/下添加bq27501驱动的过程,然后再简单说明在drivers/char/目录下添加的过程。

2. 在/bq27501下面新建一个Makefile文件。向里面添加代码:
obj-$(CONFIG_BQ27501)+=bq27501.o
此时,构建系统运行就将会进入 bq27501/ 目录下,并且将bq27501.c 编译为 bq27501.o
3. 在/bq27501下面新建Kconfig文件。添加代码:
menu "bq27501 driver"

config BQ27501
tristate"BQ27501"
default y
---help---
Say 'Y' here, it will be compiled into thekernel; If you choose 'M', it will be compiled into a mole named asbq27501.ko.
endmenu
注意:help中的文字不能加回车符,否则make menuconfig编译的时候会报错。
4. 修改/drivers目录下的Kconfig文件,在endmenu之前添加一条语句‘source drivers/bq27501/Kconfig’ 对于驱动程序,Kconfig 通常和源代码处于同一目录。 若建立了一个新的目录,而且也希望 Kconfig 文件存在于该目录中的话,那么就必须在一个已存在的 Kconfig 文件中将它引入,需要用上面的语句将其挂接在 drivers 目录中的Kconfig 中。

5. 修改/drivers目下Makefile文件,添加‘obj-$(CONFIG_BQ27501) +=bq27501/’。这行编译指令告诉模块构建系统在编译模块时需要进入 bq27501/ 子目录中。此时的驱动程序的编译取决于一个特殊配置 CONFIG_BQ27501 配置选项。

6. 修改arch/arm目录下的Kconfig文件,在menu "Device Drivers……endmenu"直接添加语句
source "drivers/bq27501/Kconfig"

㈢ 新人求教 驱动源码编译安装

1、安装scons
(1) 下载python2.7, 使用x86_32位,因为scons只有32位安装包可用;
(2) 下载scons2.3.0;
(3) 安装python 和 scons, 将C:\Python27\Scripts写入PATH;
(4) 下载安装pywin32 ,It is recommended you install pywin32 if you want to do parallel builds (scons -j)

2、安装boost库(1.49版本).
解压后双击bootstrap.bat,生成bjam.exe后,cd到目录c:\boost下,(将boost_1_49更名为boost了)编译boost。
编译命令:C:\boost>bjam variant=release --with-filesystem --with-thread --with-date_time --with-program_options threading=multi toolset=msvc-10.0 link=static runtime-link=static address-model=32
这是使用VS2010环境编译的release版本,编译完成后,生成C:\boost\stage\lib文件夹,下面有6个lib库:

如果要编译成debug版本,使用命令:bjam variant=debug --with-filesystem --with-thread --with-date_time --with-program_options threading=multi toolset=msvc-10.0 link=static runtime-link=static address-model=32

编译完成后,生成C:\boost\stage\lib文件夹,下面有10个lib库和dll:

此处为MongoDB文档中对于编译boost库的要求原文:
When using bjam, MongoDB expects
variant=debug for debug builds, and variant=release for release builds
threading=multi
link=static runtime-link=static for release builds
address-model=64 for 64 bit(64位的话,把32换为64)。link=static runtime-link=static,boost需要编译成静态库,因为mongodb只会去链接boost的静态库
address-model=64在win7 64环境下此项必须,不加在编译mongodb的c++ client时会出现链接错误。

3、下载mongo2.4.6源码 http://www.mongodb.org/downloads官网下载
编译Mongoclient.lib

cmd命令提示符下,cd到解压后的文件目录,例如我放在了E盘,E:\mongodb-src-r2.4.6,输入命令:
scons –-dd --32 mongoclient.lib // build C++ client driver library
Add --64 or --32 to get the 64- and 32-bit versions, respectively. Replace --release with --dd to build a debug build.
编译后在mongodb\build\win32\32\dd\client_build\生成mongoclient.lib.

4、测试程序
就用Mongodb自带的例子吧,使用VS2010打开E:\mongodb-src-r2.4.6\src\mongo\client\examples中的simple_client_demo.vcxproj,编译,会提示生成simple_client_demo.sln,保存。
使用debug模式,配置工程环境:打开工程->属性,配置Configuration Properties下的VC++ Directories,头文件路径添加C:\boost,Lib库路径添加boost的lib,以及mongodb client的lib:
C:\boost\stage\lib

E:\mongodb-src-r2.4.6\build\win32\32\dd\client_build
进入C/C++下面的Code Generation,将Runtime Library设置为Multi-threaded Debug (/MTd)
进入Linker下面的Input,设置Additional Dependencies,添加ws2_32.lib,psapi.lib,Dbghelp.lib,mongoclient.lib
将E:\mongodb-src-r2.4.6\build\win32\32\dd\mongo\base下生成的error_codes.h和error_codes.cpp文件,拷贝到E:\mongodb-src-r2.4.6\src\mongo\base目录下。
ok,编译、运行.

5、问题解决
error LNK2038: mismatch detected for '_MSC_VER': value '1700' doesn't match value '1600' in error_codes.obj
1>mongoclient_d.lib(dbclient.obj) : error LNK2038: mismatch detected for '_MSC_VER': value '1700' doesn't match value '1600' in error_codes.obj
1>mongoclient_d.lib(assert_util.obj) : error LNK2038: mismatch detected for '_MSC_VER': value '1700' doesn't match value '1600' in error_codes.obj
1>mongoclient_d.lib(jsobj.obj) : error LNK2038: mismatch detected for '_MSC_VER': value '1700' doesn't match value '1600' in error_codes.obj
1>mongoclient_d.lib(status.obj) : error LNK2038: mismatch detected for '_MSC_VER': value '1700' doesn't match value '1600' in error_codes.obj
1>mongoclient_d.lib(mutexdebugger.obj) : error LNK2038: mismatch detected for '_MSC_VER': value '1700' doesn't match value '1600' in error_codes.obj

VS的版本不匹配,lib是在更高级的版本中编译生成的,而使用的时候,是在低级版本中使用的,所以出现了不匹配的错误。例如,我在VS2010 SP1和VS2012的环境下编译的,而使用是在VS2010上使用,所以在编译时,出现了以上问题。

1>mongoclient.lib(stacktrace.obj) : error LNK2001: unresolved external symbol __imp_SymCleanup
1>mongoclient.lib(stacktrace.obj) : error LNK2001: unresolved external symbol __imp_SymGetMoleInfo64
1>mongoclient.lib(stacktrace.obj) : error LNK2001: unresolved external symbol __imp_SymInitialize
1>mongoclient.lib(stacktrace.obj) : error LNK2001: unresolved external symbol __imp_StackWalk64
1>mongoclient.lib(stacktrace.obj) : error LNK2001: unresolved external symbol __imp_SymFromAddr

在工程依赖库中添加Dbghelp.lib

其它问题,看看你手头的编译器、编译出来的boost库版本、mongoclient.lib的版本,是否对应好了。

㈣ 如何编译一个linux下的驱动模块

linux下编译运行驱动
嵌入式linux下设备驱动的运行和linux x86 pc下运行设备驱动是类似的,由于手头没有嵌入式linux设备,先在vmware上的linux上学习驱动开发。
按照如下方法就可以成功编译出hello world模块驱动。
1、首先确定本机linux版本
怎么查看Linux的内核kernel版本?
'uname'是Linux/unix系统中用来查看系统信息的命令,适用于所有Linux发行版。配合使用'uname'参数可以查看当前服务器内核运行的各个状态。
#uname -a
Linux whh 3.5.0-19-generic #30-Ubuntu SMPTue Nov 13 17:49:53 UTC 2012 i686 i686 i686 GNU/Linux

只打印内核版本,以及主要和次要版本:
#uname -r
3.5.0-19-generic

要打印系统的体系架构类型,即的机器是32位还是64位,使用:
#uname -p
i686

/proc/version 文件也包含系统内核信息:
# cat /proc/version
Linux version 3.5.0-19-generic(buildd@aatxe) (gcc version 4.7.2 (Ubuntu/Linaro 4.7.2-2ubuntu1) ) #30-UbuntuSMP Tue Nov 13 17:49:53 UTC 2012

发现自己的机器linux版本是:3.5.0-19-generic
2、下载机器内核对应linux源码
到下面网站可以下载各个版本linux源码https://www.kernel.org/
如我的机器3.5.0版本源码下载地址为:https://www.kernel.org/pub/linux/kernel/v3.x/linux-3.5.tar.bz2
下载完后,找一个路径解压,如我解压到/linux-3.5/
然后很重要的一步是:执行命令uname -r,可以看到Ubuntu的版本信息是3.5.0-19-generic
。进入linux源码目录,编辑Makefile,将EXTRAVERSION = 修改为EXTRAVERSION= -19-generic。
这些都是要配置源码的版本号与系统版本号,如果源码版本号和系统版本号不一致,在加载模块的时候会出现如下错误:insmod: error inserting 'hello.ko': -1 Invalid mole format。
原因很明确:编译时用的hello.ko的kenerl 不是我的pc的kenerl版本。

执行命令cp /boot/config-3.5.0-19-generic ./config,覆盖原有配置文件。
进入linux源码目录,执行make menuconfig配置内核,执行make编译内核。

3、写一个最简单的linux驱动代码hello.c

/*======================================================================
Asimple kernel mole: "hello world"
======================================================================*/
#include <linux/init.h>
#include <linux/mole.h>
MODULE_LICENSE("zeroboundaryBSD/GPL");
static int hello_init(void)
{
printk(KERN_INFO"Hello World enter\n");
return0;
}

static void hello_exit(void)
{
printk(KERN_INFO"Hello World exit\n ");
}

mole_init(hello_init);
mole_exit(hello_exit);

MODULE_AUTHOR("zeroboundary");
MODULE_DESCRIPTION("A simple HelloWorld Mole");
MODULE_ALIAS("a simplestmole");

4、写一个Makefile对源码进行编译
KERN_DIR = /linux-3.5
all:
make-C $(KERN_DIR) M=`pwd` moles
clean:
make-C $(KERN_DIR) M=`pwd` clean

obj-m += hello.o

5、模块加载卸载测试
insmod hello.ko
rmmod hello.ko

然后dmesg|tail就可以看见结果了

最后,再次编译驱动程序hello.c得到hello.ko。执行insmod ./hello.ko,即可正确insert模块。

使用insmod hello.ko 将该Mole加入内核中。在这里需要注意的是要用 su 命令切换到root用户,否则会显示如下的错误:insmod: error inserting 'hello.ko': -1 Operation not permitted

内核模块版本信息的命令为modinfo hello.ko
通过lsmod命令可以查看驱动是否成功加载到内核中
通过insmod命令加载刚编译成功的time.ko模块后,似乎系统没有反应,也没看到打印信息。而事实上,内核模块的打印信息一般不会打印在终端上。驱动的打印都在内核日志中,我们可以使用dmesg命令查看内核日志信息。dmesg|tail

可能还会遇到这种问题insmod: error inserting 'hello.ko': -1 Invalid mole format
用dmesg|tail查看内核日志详细错误
disagrees about version of symbolmole_layout,详细看这里。
http://www.ibm.com/developerworks/cn/linux/l-cn-kernelmoles/index.html
在X86上我的办法是:
make -C/usr/src/linux-headers-3.5.0-19-generic SUBDIRS=$PWD moles

㈤ 如何把自己的驱动编译进内核或模块

我们知道若要给Linux内核添加模块(驱动)有如下两种方式:
(1)动态方式:采用insmod命令来给运行中的linux加载模块。
(2)静态方式:修改linux的配置菜单,添加模块相关文件到源码对应目录,然后把模块直接编译进内核。
对于动态方式,比较简单,下面我们介绍如何采用静态的方式把模块添加到内核。
最终到达的效果是:在内核的配置菜单中可以配置我们添加的模块,并可以对我们添加的模块进行编译。
一. 内核的配置系统组成
首先我们要了解Linux 2.6内核的配置系统的原理,比如我们在源码下运行“make menuconfig ”为神马会出现一个图形配置菜单,配置了这个菜单后又是如何改变了内核的编译策略滴。
内核的配置系统一般由以下几部分组成:
(1)Makefile:分布在Linux内核源代码中的Makefile,定义Linux内核的编译规则。
(2)配置文件(Kconfig):给用户提供配置选项,修改该文件来改变配置菜单选项。
(3)配置工具:包括配置命令解释器(对配置脚本中使用的配置命令进行解释),配置用户界面(提供字符界面和图形界面)。这些配置工具都是使用脚本语言编写的,如Tcl/TK、Perl等。
其原理可以简述如下:这里有两条主线,一条为配置线索,一条为编译线索。配置工具根据kconfig配置脚本产生配置菜单,然后根据配置菜单的配置情况生成顶层目录下的.config,在.config里定义了配置选择的配置宏定义,如下所示:

如上所示,这里定义的这些配置宏变量会在Makefile里出现,如下所示:

然后make 工具根据Makefile里这些宏的赋值情况来指导编译。所以理论上,我们可以直接修改.config和Makefile来添加模块,但这样很麻烦,也容易出错,下面我们将会看到,实际上我们有两种方法来很容易的实现。

二. 如何添加模块到内核
实际上,我们需要做的工作可简述如下:
(1)将编写的模块或驱动源代码(比如是XXOO)复制到Linux内核源代码的相应目录。
(2)在该目录下的Kconfig文件中依葫芦画瓢的添加XXOO配置选项。
(3)在该目录的Makefile文件中依葫芦画瓢的添加XXOO编译选项。
可以看到,我们奉行的原则是“依葫芦画瓢”,主要是添加。
一般的按照上面方式又可出现两种情况,一种为给XXOO驱动添加我们自己的目录,一种是不添加目录。两种情况的处理方式有点儿不一样哦。

三. 不加自己目录的情况
(1)把我们的驱动源文件(xxoo.c)放到对应目录下,具体放到哪里需要根据驱动的类型和特点。这里假设我们放到./driver/char下。
(2)然后我们修改./driver/char下的Kconfig文件,依葫芦添加即可,如下所示:

注意这里的LT_XXOO这个名字可以随便写,但需要保持这个格式,他并不需要跟驱动源文件保持一致,但最好保持一致,等下我们在修改Makefile时会用到这个名字,他将会变成CONFIG_LT_XXOO,那个名字必须与这个名字对应。如上所示,tristate定义了这个配置选项的可选项有几个,help定义了这个配置选项的帮助信息,具体更多的规则这里不讲了。

(3)然后我们修改./driver/char下的Makefile文件,如下所示:

这里我们可以看到,前面Kconfig里出现的LT_XXOO,在这里我们就需要使用到CONFIG_XXOO,实际上逻辑是酱汁滴:在Kconfig里定义了LT_XXOO,然后配置完成后,在顶层的.config里会产生CONFIG_XXOO,然后这里我们使用这个变量。
到这里第一种情况下的添加方式就完成了。
四. 添加自己目录的情况
(1)在源码的对应目录下建立自己的目录(xxoo),这里假设为/drivers/char/xxoo 。
(2) 把驱动源码放到新建的xxoo目录下,并在此目录下新建Kconfig和Makefile文件。然后给新建的Kconfig和Makefile添加内容。
Kconfig下添加的内容如下:

这个格式跟之前在Kconfig里添加选项类似。
Makefile里写入的内容就更少了:

添加这一句就可以了。
(3)第三也不复杂,还是依葫芦画瓢就可以了。
我们在/drivers/char目录下添加了xxoo目录,我们总得在这个配置系统里进行登记吧,哈哈,不然配置系统怎么找到们呢。由于整个配置系统是递归调用滴,所以我们需要在xxoo的父目录也即char目录的Kconfig和Makefile文件里进行登记。具体如下:
a). 在drivers/char/Kconfig中加入:source “drivers/char/xxoo/Kconfig”
b). 在drivers/char/Makefile中加入:obj-$(CONFIG_LT_XXOO) += xxoo/
添加过程依葫芦画瓢就可以了,灰常滴简单。

㈥ vs2010如何编译驱动

1、安装VS2010,安装WDK 7.0(DDK);

2、新建VC++->Empty Project

3、打开Configuration Manager 并新建一个名称为“ dirver ”的Solution Configuration 并将“dirver” 设为Active Solution Configuration .

4、打开View-> property Manager。

5、在"dirver" solution configuration 上点击右键,选择Add new property Sheet。取名为“dirverProperty”. 并对他进下以下设置。

5.1. C\C++ - General - Debug Information Format = Program Database (/Zi)
5.2. C\C++ - Preprocessor - Preprocessor Definitions = _X86_ [add also DBG for Debug config]
【WIN32;_DEBUG;_X86_;i386;STD_CALL;CONDITION_HANDLING;WIN32_LEAN_AND_MEAN;NT_UP;SRVDBG;DBG;_IDWBUILD;_WIN32_WINNT=0x0400;% (PreprocessorDefinitions)】
5.3. C\C++ - Code Generation - Enable C++ Exceptions = No
5.4. C\C++ - Code Generation - Basic Runtime Checks = Default
5.5. C\C++ - Code Generation - Buffer Security Check = No (/GS-)
5.6. C\C++ - Advanced - Calling Convention = __stdcall (/Gz)
5.7. C\C++ - Advanced - Compile As = Compile as C Code (/TC) [if you are going to use plain C]
5.8. Linker - General - Output File = $(OutDir)\$(ProjectName).sys
5.9. Linker - General - Enable Incremental Linking = Default
5.10. Linker - Input - Additional Dependencies = ntoskrnl.lib hal.lib $(NOINHERIT) [add here needed libs here e.g. ntoskrnl.lib hal.lib]
【不知道上面是不是笔误,应该为:ntoskrnl.lib;hal.lib;%(AdditionalDependencies)】
5.11. Linker - Input - Ignore All Default Libraries = Yes (/NODEFAULTLIB)
5.12. Linker - Manifest File - Generate Manifest = No
5.13. Linker - System - SubSystem = Native (/SUBSYSTEM:NATIVE)
5.14. Linker - System - Driver = Driver (/DRIVER)
5.15. Linker - Advanced - Entry Point = DriverEntry
5.16. Linker - Advanced - Base Address = 0x10000
5.17. Linker - Advanced - Randomized Base Address = Disable (/DYNAMICBASE:NO)
【这个也是错误的:应该置空】
5.18. Linker - Advanced - Data Execution Prevention (DEP) = Disable (/NXCOMPAT:NO)
【这个也是错误的:应该置空】

6. Config VC++ Directories
6.1 Open Open up property manager by clicking on Menu View->Property Manager.
6.2 Expand the project node and then the Configuration|Platform nodes, you will see "Microsoft.cpp.<Platform>.users" file for each Configuration|Platform. These are the files

for the global settings, similar to the old tools/Options/VC++ Directories.
6.3 Multi-Select "Microsoft.cpp.<Platform>.users", right click and bring up the property page window
6.4 In the property page window, click on "VC++ Directories" (for example) in the left pane, add new paths for the directories such as "Include Directories". separated by

semicolons
(eg:Include Directories config As:
$(ddkroot)\INC
$(ddkroot)\INC\WNET
$(ddkroot)\INC\DDK\WNET
Library Directories config As:
$(ddkroot)\LIB\WNET\I386
)
6.5 Make sure to save the settings before shutting down Visual Studio.
6.6 Re-launch Visual Studio and the new settings will be in effect.
6.7 Note: If you would like to only change the settings for one project, you can right click on the project and bring up the property page. Change the settings for “VC++

Directories”, these settings will be persisted to the project file.
七. OK. Have done. Now you can test it with simple code, e.g.:

#include "ntddk.h"

NTSTATUS
DriverEntry(PDRIVER_OBJECT DriverObject,PUNICODE_STRING RegistryPath)
{
return STATUS_UNSUCCESSFUL;
}

特别说明:
1.
Visual Studio 2010 在智能设备开发方面只支持Windows Phone OS 7.0。如果你要为Windows CE 5.0和Windows Mobile 6.5开发应用程序,请安装Visual Studio 2008。
2.
做驱动开发时,SDK的版本要和WDK的版本一致,即Win7 WDK要配Win7 SDK,否则会出现编译错误。VS2010里集成了Windows SDK 7.0A。
3.
如果出现类似如下编译错误,解决方法是:拷贝C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\sal.h,然后覆盖掉C:\WinDDK\7600.16385.1\inc\api\sal.h。

C:\Program Files\Microsoft Visual Studio 10.0\VC\include\crtdefs.h(550): error C2143: syntax error : missing ')' before 'const'
C:\Program Files\Microsoft Visual Studio 10.0\VC\include\crtdefs.h(550): error C2143: syntax error : missing '{' before 'const'
.......

热点内容
gms源码 发布:2025-02-05 08:55:01 浏览:780
搭建的服务器怎么连接不了 发布:2025-02-05 08:49:05 浏览:656
wordbox安卓怎么玩 发布:2025-02-05 08:36:12 浏览:531
车内安卓大屏怎么联网 发布:2025-02-05 08:33:47 浏览:342
安卓手机中的投影在哪里 发布:2025-02-05 08:01:57 浏览:595
php调用定义函数 发布:2025-02-05 08:00:30 浏览:452
ubuntujava环境变量 发布:2025-02-05 07:57:13 浏览:443
sql语句on 发布:2025-02-05 07:41:42 浏览:598
取消电脑密码怎么设置8 发布:2025-02-05 07:24:16 浏览:394
洗脑编程 发布:2025-02-05 07:23:52 浏览:950