我的代码遇到链接器错误.我正在尝试使用Win-7 X64位m/c中的Visual Studio命令提示符(2010)进行编译. 我看到的错误如下.
I am facing linker error with my code. I am trying to compile with Visual Studio command Prompt (2010) in Win-7 X64 bit m/c. The error which i see are as below.
dust2.obj
dust2.obj
dust2.obj:错误LNK2019:未解析的外部符号_NtOpenFile @ 24被引用 在函数_main
dust2.obj : error LNK2019: unresolved external symbol _NtOpenFile@24 referenced in function _main
dust2.obj:错误LNK2019:未解析的外部符号_RtlAnsiStringToUnicodeStr _main函数中引用的ing @ 12
dust2.obj : error LNK2019: unresolved external symbol _RtlAnsiStringToUnicodeStr ing@12 referenced in function _main
dust2.obj:错误LNK2019:未解析的外部符号_RtlInitAnsiString @ 8引用 放在函数_main
dust2.obj : error LNK2019: unresolved external symbol _RtlInitAnsiString@8 refer enced in function _main
dust2.exe:致命错误LNK1120:3个未解决的外部因素
dust2.exe : fatal error LNK1120: 3 unresolved externals
我的代码的简化版是这样的:
The simplified version of my code is like this:
#include <windows.h> #include <iostream> #include <Winternl.h> using namespace std; int main() { NTSTATUS Status; OBJECT_ATTRIBUTES Obja; HANDLE SourceFile; PUNICODE_STRING PathName=0; PANSI_STRING p_path=0; const char* ccp_path = "D:\\txt.txt"; RtlInitAnsiString( p_path,ccp_path ); RtlAnsiStringToUnicodeString( PathName, p_path, true ); IO_STATUS_BLOCK IoStatusBlock; wprintf(L"%s", PathName->Buffer); InitializeObjectAttributes( &Obja, PathName, OBJ_CASE_INSENSITIVE, NULL, NULL ); Status = NtOpenFile( &SourceFile, FILE_LIST_DIRECTORY | FILE_READ_EA | FILE_READ_ATTRIBUTES, &Obja, &IoStatusBlock, FILE_SHARE_READ | FILE_SHARE_WRITE, FILE_DIRECTORY_FILE | FILE_OPEN_FOR_BACKUP_INTENT | FILE_OPEN_REPARSE_POINT ); if(SourceFile == INVALID_HANDLE_VALUE){ printf("\nError: Could not open file\n"); return 0; } cout<<endl<<endl; system("pause"); return 0; }在该论坛的另一篇文章中,提到了此类问题的解决方案,其中包括 #pragma .
In another post in this forum the solution of these kind of problem was mention to include a #pragma.
我通过添加#pragma这样的方式尝试了此解决方案
I tried this solution by adding #pragma like this
#pragma comment(lib, "ntdll")但是在编译时,我看到另一个错误,显示为"LINK:致命错误LNK1104:无法打开文件'ntdll.lib'".
but on compilation i see another error that says "LINK : fatal error LNK1104: cannot open file 'ntdll.lib'".
非常感谢您为解决此问题所提供的帮助.谢谢.
I will much appreciate your help to resolve this problem. Thanks..
推荐答案这些函数不能直接调用,因为它们属于内部API,并且不会通过任何库公开.您需要使用GetProcAddress获取这些函数的地址.
These functions cannot be called directly because they belong to internal API and are not exposed through any of the libraries. You need to obtain addresses of these function using GetProcAddress.
有关更多信息,请在此处
更多推荐
LNK2019无法解析的外部符号NtOpenFile
发布评论