gpt4 book ai didi

c++ - 在 KMDF 驱动程序中包含 fstream.h 后出现链接器错误

转载 作者:行者123 更新时间:2023-11-28 05:36:04 27 4
gpt4 key购买 nike

我是驱动程序开发的新手。这是我的代码:

#include <ndis.h>
#include <fwpmk.h>
#include <fwpvi.h>
#include <fwpsk.h>
#include <fstream.h>
#pragma comment(lib, "libcpmtd.lib")

extern "C" {

NTSTATUS DriverEntry(
_In_ struct _DRIVER_OBJECT *DriverObject,
_In_ PUNICODE_STRING RegistryPath
)
{
ofstream s("D:\\somefile.txt");
s << "driver initialized.";
return 0;
}
}

产生以下错误列表:

Severity    Code    Description Project File    Line    Suppression State
Error LNK2019 unresolved external symbol "public: virtual __thiscall ios::~ios(void)" (??1ios@@UAE@XZ) referenced in function "public: void __thiscall ofstream::`vbase destructor'(void)" (??_Dofstream@@QAEXXZ) KMDF Driver1 D:\Projects\C++\KMDF Driver1\KMDF Driver1\Source.obj 1
Error LNK2019 unresolved external symbol "public: class ostream & __thiscall ostream::operator<<(char const *)" (??6ostream@@QAEAAV0@PBD@Z) referenced in function _DriverEntry@8 KMDF Driver1 D:\Projects\C++\KMDF Driver1\KMDF Driver1\Source.obj 1
Error LNK2019 unresolved external symbol "public: __thiscall ofstream::ofstream(char const *,int,int)" (??0ofstream@@QAE@PBDHH@Z) referenced in function _DriverEntry@8 KMDF Driver1 D:\Projects\C++\KMDF Driver1\KMDF Driver1\Source.obj 1
Error LNK2019 unresolved external symbol "public: virtual __thiscall ofstream::~ofstream(void)" (??1ofstream@@UAE@XZ) referenced in function "public: void __thiscall ofstream::`vbase destructor'(void)" (??_Dofstream@@QAEXXZ) KMDF Driver1 D:\Projects\C++\KMDF Driver1\KMDF Driver1\Source.obj 1
Error LNK2001 unresolved external symbol "public: static int const filebuf::openprot" (?openprot@filebuf@@2HB) KMDF Driver1 D:\Projects\C++\KMDF Driver1\KMDF Driver1\Source.obj 1
Error LNK1120 5 unresolved externals KMDF Driver1 D:\Projects\C++\KMDF Driver1\Debug\KMDFDriver1.sys 1

最佳答案

此符号 (ios, ofstream) - 来自 msvcrt.dll(或者即使使用静态 libc - 例如它具有来自 kernel32.dll 的依赖项)并且不能在内核模式下使用。您需要删除“ostream s”——使用 DbgPrint 或 ZwCreateFile/ZwWriteFile 进行日志记录

关于c++ - 在 KMDF 驱动程序中包含 fstream.h 后出现链接器错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38279845/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com