ReactOS学习笔记(1)-《Windows内核设计思想》随书源代码编译问题

来源:互联网 发布:网络翻译成英文 编辑:程序博客网 时间:2024/06/08 09:00
相信很多同学在使用《Windows内核设计思想》随书源代码中的VMWare虚拟机进行调试的时候会发现:启动虚拟机后通过快捷方式运行Windbg,Windbg执行到第一个断点(osloader!DbgBreakPoint+0x9)时,源代码文件窗口并没有像书中描述的一样弹出,解决这个问题的方式如下:
  1. 随书源代码的压缩文件名为25314.rar,解压后文件夹名为25314,需将其重命名为code并置于E盘根目录下。
  2. 如果没有E盘,使用subst命令将code的父文件夹映射成E盘。
  3. 最后,从E盘下的目录打开虚拟机就可以成功地跟踪到断点处的源代码。
如果修改源代码并进行重新编译(笔者使用Windows7+VS2015),会发现如下错误:
11>ntoskrnl.rc(10): fatal error RC1015: cannot open include file 'afxres.h'.
解决方法:将afxres.h修改为windows.h。源代码中并没有使用MFC,这样的改动是可以的。
再次编译源代码,会出现如下错误:

SeverityCodeDescriptionProjectFileLineErrorLNK1181cannot open input file 'ntoskrnl.lib'acpiE:\code\ntos\acpi\LINK1ErrorLNK1181cannot open input file 'ntoskrnl.lib'uniataE:\code\ntos\uniata\LINK1ErrorLNK1181cannot open input file 'ntoskrnl.lib'scsiportE:\code\ntos\scsiport\LINK1ErrorLNK1181cannot open input file 'ntoskrnl.lib'pciE:\code\ntos\pci\LINK1ErrorLNK1181cannot open input file 'ntoskrnl.lib'ntfsE:\code\ntos\ntfs\LINK1ErrorLNK1181cannot open input file 'ntoskrnl.lib'diskE:\code\ntos\disk\LINK1

上述问题的解决办法:在各自工程属性的Linker->General->Additional Library Directories中加入"..\Debug"路径。
再次编译源代码,会出现如下错误:

SeverityCodeDescriptionProjectFileLineErrorLNK1181cannot open input file 'hal.lib'acpiE:\code\ntos\acpi\LINK1ErrorLNK1181cannot open input file 'hal.lib'diskE:\code\ntos\disk\LINK1ErrorLNK1181cannot open input file 'hal.lib'pciE:\code\ntos\pci\LINK1ErrorLNK1181cannot open input file 'hal.lib'ntfsE:\code\ntos\ntfs\LINK1ErrorLNK1181cannot open input file 'hal.lib'scsiportE:\code\ntos\scsiport\LINK1ErrorLNK1181cannot open input file 'hal.lib'uniataE:\code\ntos\uniata\LINK1

上述问题的解决办法:在各自工程属性的Linker->General->Additional Library Directories中加入"..\system32"路径。
再次编译源代码,出现如下错误:

SeverityCodeDescriptionProjectFileLineErrorLNK1181cannot open input file 'ntstrsafe.lib'acpiE:\code\ntos\acpi\LINK1ErrorLNK1181cannot open input file 'ntstrsafe.lib'diskE:\code\ntos\disk\LINK1ErrorLNK1181cannot open input file 'ntstrsafe.lib'ntfsE:\code\ntos\ntfs\LINK1ErrorLNK1181cannot open input file 'ntstrsafe.lib'pciE:\code\ntos\pci\LINK1ErrorLNK1181cannot open input file 'scsiport.lib'uniataE:\code\ntos\uniata\LINK1

解决办法: 1. 将ntstrsafe.lib,int64.lib,exsup.lib从上述工程中删除。2. Linker->Advanced->Image Has Safe Exception Handlers选择No (/SAFESEH:NO)。
再次编译,出现如下错误:

SeverityCodeDescriptionProjectFileLineErrorLNK11202 unresolved externalsntfsE:\code\ntos\Debug\ntfs.sys1ErrorLNK2019unresolved external symbol _KeEnterCriticalRegion@0 referenced in function _NtfsCreate@8ntfsE:\code\ntos\ntfs\create.obj1ErrorLNK2019unresolved external symbol _KeLeaveCriticalRegion@0 referenced in function _NtfsCreate@8ntfsE:\code\ntos\ntfs\create.obj1

解决办法是:在KeEnterCriticalRegionEx和KeLeaveCriticalRegionEx的函数签名void后添加NTAPI。
到此时为止,工程编译成功!
如果使用Windbg进行调试,会出现如下问题:
Break instruction exception - code 80000003 (first chance)
osloader!_KiTrap06:
004179d0 cc              int     3
解决此问题的办法:设置所有工程属性表中的C/C++->Code Generation->Enable Enhanced Instruction Set为No Enhanced Instructions(/arch:IA32)。重新编译即可。
再次使用Windbg进行调试,还会出现问题,uncheck所有工程属性表中的Linker->Input->Additional Dependencies->Inherit from parent or project defaults再次编译,即可顺利运行如下位置。
DECLSPEC_NORETURN VOID FASTCALL KiTrapReturn(IN PKTRAP_FRAME TrapFrame)
{
    UNIMPLEMENTED
    _asm int 3 // 本书暂时讲解到此
}
阅读全文
0 0