title: LNK2019 unresolved external symbol NtOpenFile
body: <p>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.</p>
  
  <blockquote>
    <p>dust2.obj</p>
    
    <p>dust2.obj : error LNK2019: <strong>unresolved external symbol _NtOpenFile</strong>@24 referenced
    in function _main</p>
    
    <p>dust2.obj : error LNK2019: <strong>unresolved external symbol _RtlAnsiStringToUnicodeStr</strong>
    ing@12 referenced in function _main</p>
    
    <p>dust2.obj : error LNK2019: <strong>unresolved external symbol _RtlInitAnsiString</strong>@8 refer
    enced in function _main</p>
    
    <p>dust2.exe : fatal error LNK1120: 3 unresolved externals</p>
  </blockquote>
  
  <p>The simplified version of my code is like this:</p>
  
  <pre><code>   #include &lt;windows.h&gt;
     #include &lt;iostream&gt;
     #include &lt;Winternl.h&gt;
  
     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-&gt;Buffer);
          InitializeObjectAttributes(
              &amp;Obja,
              PathName,
              OBJ_CASE_INSENSITIVE,
              NULL,
              NULL
          );
          Status = NtOpenFile(
                       &amp;SourceFile,
                       FILE_LIST_DIRECTORY | FILE_READ_EA | FILE_READ_ATTRIBUTES,
                       &amp;Obja,
                       &amp;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&lt;&lt;endl&lt;&lt;endl;
          system("pause");
          return 0;
  
  }
  </code></pre>
  
  <p>In another post in this forum the solution of these kind of problem was mention to include a <a href="https://stackoverflow.com/questions/3297920/unresolved-external-symbol">#pragma</a>.</p>
  
  <p>I tried this solution by adding #pragma like this</p>
  
  <pre><code>#pragma comment(lib, "ntdll")
  </code></pre>
  
  <p>but on compilation i see another error that says "LINK : fatal error LNK1104: cannot open file 'ntdll.lib'".</p>
  
  <p>I will much appreciate your help to resolve this problem. Thanks..</p>