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

R

Richard Lionheart

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:

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:

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
 
A

Alf P. Steinbach

* Richard Lionheart:
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) *******************

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

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

John Carson

Richard Lionheart said:
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:


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:


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

This is Microsoft specific. Such questions are better asked in

microsoft.public.vc.language

or

microsoft.public.vc.ide_general

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.
 
B

Ben Pope

Richard said:
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"

// this header is non standard
void main()

// main ALWAYS returns an int
{
printf("Hello, World\n");
}
***************** (end) *******************

with the command "cl HelloWorld.cpp" and got:

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
 
M

Marcus Kwok

Ben Pope said:
Hello world in C++ is:

#include <iostream>

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

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

Ben Pope

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

I knew I'd get it wrong :)

Ben Pope
 
R

Richard Lionheart

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
 
R

Richard Lionheart

Hi Ben,

< I knew I'd get it wrong :)

You didn't get it wrong this time!!

Regards,
Richard
 
R

Richard Lionheart

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
 
R

Richard Lionheart

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,020
Latest member
GenesisGai

Latest Threads

Top