當前位置:首頁 » 編程軟體 » 驅動編譯命令

驅動編譯命令

發布時間: 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'
.......

熱點內容
java16進制字元串 發布:2025-02-05 10:38:13 瀏覽:643
創業團隊配置有哪些 發布:2025-02-05 10:37:40 瀏覽:630
王者鍵盤怎麼設置安卓 發布:2025-02-05 10:32:01 瀏覽:373
阿里雲輕量伺服器ip搭建 發布:2025-02-05 10:24:46 瀏覽:487
編程高精度 發布:2025-02-05 10:22:28 瀏覽:230
使命召喚如何配置爆炸狙 發布:2025-02-05 10:08:12 瀏覽:143
java訪問共享目錄 發布:2025-02-05 10:03:56 瀏覽:281
行車記錄儀存儲卡多大合適 發布:2025-02-05 09:35:21 瀏覽:112
oppo手機鎖屏密碼忘了怎麼辦 發布:2025-02-05 09:33:50 瀏覽:124
phprsa演算法 發布:2025-02-05 09:33:48 瀏覽:231