23

I found this sample code on the msdn library

#include <iostream>

int main()
{
    std::cout << "This is a native C++ program." << std::endl;
    return 0;
}

from How to Compile a Native C++ Program From the Command Line I store this code in file.cpp I then go to the command prompt and type this

The output is as follows:

Current Path> cl /EHsc file.cpp

Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 15.00.30729.01 for 80x86

Copyright (C) Microsoft Corporation. All rights reserved.

file.cpp file.cpp(1) : fatal error C1034: iostream: no include path set

I have the path variable set to the mirosoft sdk but I don't know what to do.

I have tried multiple files like string.h and stdlib.h, but still no luck.

Community
  • 1
  • 1

2 Answers2

32

The Visual C++ compiler depends on a whole bunch of environment variables. The easiest way to get these set right is using the "Visual Studio Command Prompt" item created on the Start menu during the install, or running vcvars32.bat from the program directory.

Otherwise, you'll have to set INCLUDE= and LIB= variables to the proper directories before getting a successful compile.

Ben Voigt
  • 277,958
  • 43
  • 419
  • 720
  • 2
    That's step 1 in the linked article. Without it, cl.exe won't run either. – Hans Passant Dec 22 '10 at 01:13
  • I originally wanted to use cl.exe in the command prompt rather than the visual studio one for convenience purposes the first time I ran cl.exe I got a dll missing complaint so I found the dll and copied it over than I used it and it simply didn't work I knew it had something to do with environment variables but I thought having my path variable have the include and lib directory would be enough... woops –  Dec 22 '10 at 01:23
  • @Luck: If you have the path set, you can just type `vcvars32` in any command prompt and it will properly set all the other variables you need. – Ben Voigt Dec 22 '10 at 04:09
3

Did you really follow those instructions and use the Visual Studio command prompt, the one that sets up the directories the compiler should look in? If you did, you need to set up the environment variables specified in that article to point where they belong, or recreate the shell .bat file.

Robert
  • 6,412
  • 3
  • 24
  • 26