"cl HelloWorld.cpp" => "std.afx" not found

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Richard Lionheart

    #1

    "cl HelloWorld.cpp" => "std.afx" not found

    Hi All,

    I've got Visual Studio .Net installed, but I don't know it very well.
    So I tried to create a plain old Win32 using the command-line complier.
    I tried to compile:

    ************ HelloWorld.cpp *************
    #include "stdafx.h"

    void main()
    {
    printf("Hello, World\n");
    }
    *************** ** (end) *************** ****

    with the command "cl HelloWorld.cpp" and got:
    [color=blue][color=green]
    >> "HelloWorld.cpp (1) : fatal error C1083: Cannot open include file: 'stdafx.h':
    >> No such file or directory"/[/color][/color]

    I thought that some environment variable that the compiler wanted
    wasn't there, so I ran vcvars32.bat, but that didn't help.

    I checked stdafx.h's (and stdafx.cpp's) existence/location: I found a
    slew of them in:
    F:\Program Files\Microsoft Visual Studio 8\VC\VCWizards\ AppWiz
    subdirectories:
    [color=blue][color=green]
    >> .NET\ClassLibra ry\Templates\10 33
    >> .NET\Console\Te mplates\1033
    >> .NET\WinForm\Te mplates\1033
    >> Generic\Applica tion\Templates\ 1033[/color][/color]

    I suspect that all the stdafx header/program files are centered on .Net
    connections so that I need to reinstall VC6.0 (and its Service Packs if
    I can find them).

    Any suggestions/opinions.

    TIA,
    Richard

  • Alf P. Steinbach

    #2
    Re: "cl HelloWorld.cpp& quot; => "std.afx&q uot; not found

    * Richard Lionheart:[color=blue]
    >
    > I've got Visual Studio .Net installed, but I don't know it very well.
    > So I tried to create a plain old Win32 using the command-line complier.
    > I tried to compile:
    >
    > ************ HelloWorld.cpp *************
    > #include "stdafx.h"
    >
    > void main()
    > {
    > printf("Hello, World\n");
    > }
    > *************** ** (end) *************** ****[/color]

    Since you're posting to a C++ group, why didn't you try a C++ program?

    Search the web for C++ "Hello, world!".

    --
    A: Because it messes up the order in which people normally read text.
    Q: Why is it such a bad thing?
    A: Top-posting.
    Q: What is the most annoying thing on usenet and in e-mail?

    Comment

    • John Carson

      #3
      Re: "cl HelloWorld.cpp& quot; => "std.afx&q uot; not found

      "Richard Lionheart" <RLMuller@USCom puterGurus.com> wrote in message
      news:1142936059 .930727.245290@ v46g2000cwv.goo glegroups.com[color=blue]
      > Hi All,
      >
      > I've got Visual Studio .Net installed, but I don't know it very well.
      > So I tried to create a plain old Win32 using the command-line
      > complier. I tried to compile:
      >
      > ************ HelloWorld.cpp *************
      > #include "stdafx.h"
      >
      > void main()
      > {
      > printf("Hello, World\n");
      > }
      > *************** ** (end) *************** ****
      >
      > with the command "cl HelloWorld.cpp" and got:
      >[color=green][color=darkred]
      >>> "HelloWorld.cpp (1) : fatal error C1083: Cannot open include file:
      >>> 'stdafx.h': No such file or directory"/[/color][/color]
      >
      > I thought that some environment variable that the compiler wanted
      > wasn't there, so I ran vcvars32.bat, but that didn't help.
      >
      > I checked stdafx.h's (and stdafx.cpp's) existence/location: I found a
      > slew of them in:
      > F:\Program Files\Microsoft Visual Studio 8\VC\VCWizards\ AppWiz
      > subdirectories:
      >[color=green][color=darkred]
      >>> .NET\ClassLibra ry\Templates\10 33
      >>> .NET\Console\Te mplates\1033
      >>> .NET\WinForm\Te mplates\1033
      >>> Generic\Applica tion\Templates\ 1033[/color][/color]
      >
      > I suspect that all the stdafx header/program files are centered on
      > .Net connections so that I need to reinstall VC6.0 (and its Service
      > Packs if I can find them).
      >
      > Any suggestions/opinions.
      >
      > TIA,
      > Richard[/color]

      This is Microsoft specific. Such questions are better asked in

      microsoft.publi c.vc.language

      or

      microsoft.publi c.vc.ide_genera l

      Microsoft's compiler offers the option of pre-compiled headers, which, once
      compiled, reduce compilation times. This is usually accomplished with a pair
      files:

      stdafx.h
      stdafx.cpp

      The first contains widely used inclusions, e.g.,

      #include <windows.h>
      #include <vector>

      the second just #includes stdafx.h.

      The contents of stdafx.h can vary from project to project. If you want to
      use these, then you either have to define them yourself or let the IDE's
      wizard generate them for you when you create a project.

      For simple hello world type applications, you may wish to forget about
      precompiled headers entirely. If so, just delete any reference to stdafx.h
      from your source files and #include whatever headers you need in the usual
      way.


      --
      John Carson



      Comment

      • Ben Pope

        #4
        Re: &quot;cl HelloWorld.cpp& quot; =&gt; &quot;std.afx&q uot; not found

        Richard Lionheart wrote:[color=blue]
        > Hi All,
        >
        > I've got Visual Studio .Net installed, but I don't know it very well.
        > So I tried to create a plain old Win32 using the command-line complier.
        > I tried to compile:
        >
        > ************ HelloWorld.cpp *************
        > #include "stdafx.h"[/color]

        // this header is non standard
        [color=blue]
        > void main()[/color]

        // main ALWAYS returns an int
        [color=blue]
        > {
        > printf("Hello, World\n");
        > }
        > *************** ** (end) *************** ****
        >
        > with the command "cl HelloWorld.cpp" and got:
        >[color=green][color=darkred]
        >>> "HelloWorld.cpp (1) : fatal error C1083: Cannot open include file: 'stdafx.h':
        >>> No such file or directory"/[/color][/color][/color]

        You don't need it, so don't include it at the top.

        If you need to know how to use your compiler, then post to a newsgroup
        where use of your compiler is topical.

        Hello world in C++ is:

        #include <iostream>

        int main() {
        std::cout << "Hello World" << std::endl;
        }

        Ben Pope
        --
        I'm not just a number. To many, I'm known as a string...

        Comment

        • Marcus Kwok

          #5
          Re: &quot;cl HelloWorld.cpp& quot; =&gt; &quot;std.afx&q uot; not found

          Ben Pope <benpope81_REMO VE_@gmail.com> wrote:[color=blue]
          > Hello world in C++ is:
          >
          > #include <iostream>[/color]

          #include <ostream> // for std::endl
          [color=blue]
          > int main() {
          > std::cout << "Hello World" << std::endl;
          > }[/color]

          Some compilers may or may not implicitly #include <ostream> in
          <iostream> (for example, HP aCC's standard library does not).

          --
          Marcus Kwok

          Comment

          • Ben Pope

            #6
            Re: &quot;cl HelloWorld.cpp& quot; =&gt; &quot;std.afx&q uot; not found

            Marcus Kwok wrote:[color=blue]
            > Ben Pope <benpope81_REMO VE_@gmail.com> wrote:[color=green]
            >> Hello world in C++ is:
            >>
            >> #include <iostream>[/color]
            >
            > #include <ostream> // for std::endl
            >[color=green]
            >> int main() {
            >> std::cout << "Hello World" << std::endl;
            >> }[/color]
            >
            > Some compilers may or may not implicitly #include <ostream> in
            > <iostream> (for example, HP aCC's standard library does not).[/color]

            I knew I'd get it wrong :)

            Ben Pope
            --
            I'm not just a number. To many, I'm known as a string...

            Comment

            • Richard Lionheart

              #7
              Re: &quot;cl HelloWorld.cpp& quot; =&gt; &quot;std.afx&q uot; not found

              Hi Ben,

              Great reply. I got a warning to add a switch:

              cl HelloWorld.cpp /EHsc

              Got HelloWorld.obj.

              I'm 95% home! I've got to find another switch to get the .exe.

              Thank you very much for posting a correct version.

              Regards,
              Richard

              Comment

              • Richard Lionheart

                #8
                Re: &quot;cl HelloWorld.cpp& quot; =&gt; &quot;std.afx&q uot; not found

                Hi Ben,

                < I knew I'd get it wrong :)

                You didn't get it wrong this time!!

                Regards,
                Richard

                Comment

                • Richard Lionheart

                  #9
                  Re: &quot;cl HelloWorld.cpp& quot; =&gt; &quot;std.afx&q uot; not found

                  Hi John,

                  Thanks for reminders. I used to know that but I've been out of the
                  programming business for 5 years. You'd be surprised at how much one
                  can forget in that time.

                  Regards,
                  Richard

                  Comment

                  • Richard Lionheart

                    #10
                    Re: &quot;cl HelloWorld.cpp& quot; =&gt; &quot;std.afx&q uot; not found

                    Hi Marcus,

                    Thanks for the additional info. Happily, it wasn't problem in in
                    Visual Studio .Net environment. I'm accessing via the command line to
                    avoid the way VS has complicated things in VC++, or that's how it seems
                    to me.

                    Ben Pope's suggestion worked great after a applied the compiler
                    direction to add some flags.

                    Regards,
                    Richard

                    Comment

                    Working...