From: Larry Lindstrom on
Hi Folks:

Developing with VS 2008 Pro.

The generous people on this newsgrup have pulled my
chestnuts out of the fire many times over the course
of several Windows development projects, and I'm always
grateful.

However, I haven't seen a response to my question
about nmake, so it's time to go a different direction.

I need to learn nmake's features so I can fix this
myself. As stated in that post, I've used make on
Unix systems with the target, dependencies and
statements explicitly spelled out. But there are
other ways of using this utility and I need to
understand how they work.

I know nmake isn't make, but I'm going to use an
older O'Reilly book on make to get started.

First example is "nmake hello_world.exe".

This is the hello_world.cpp source:

----

#include <windows.h>
#include <iostream>

int main()
{
cout << "Hello World\n";

return (0);
}

----

C:>nmake hello_world.exe

Microsoft (R) Program Maintenance Utility Version 9.00.21022.08
Copyright (C) Microsoft Corporation. All rights reserved.

cl hello_world.cpp
Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 15.00.21022.08
for 80x86
Copyright (C) Microsoft Corporation. All rights reserved.

hello_world.cpp
C:\Program Files\Microsoft Visual Studio 9.0\VC\INCLUDE\xlocale(342) :
warning C
4530: C++ exception handler used, but unwind semantics are not enabled.
Specify
/EHsc
hello_world.cpp(6) : error C2065: 'cout' : undeclared identifier
NMAKE : fatal error U1077: '"C:\Program Files\Microsoft Visual Studio
9.0\VC\BIN
\cl.EXE"' : return code '0x2'
Stop.

----

I've tried this with and without the #include <windows>. Same
result either way.

It can't find cout? I've written a hundred thousand lines of C++
code WIN32 code, and I don't use cout. Why can't Visual Studion 2008
find it for this little sample?

And what's this complaint about the exception handler?

Thanks
Larry

From: Alf P. Steinbach on
* Larry Lindstrom:
>
> The generous people on this newsgrup have pulled my
> chestnuts out of the fire many times over the course
> of several Windows development projects

I prefer to not handle your chestnuts, so I'll just point out to you where the
fire is, and then you can hopefully find your own way out of it.


[snip]
> #include <windows.h>

You don't need that, and in C++ that's not the way include this header. If you
include it, you should first define STRICT, NOMINMAX, UNICODE and _UNICODE. And
perhaps also macro symbols that define which Windows API version you need.


> #include <iostream>
>
> int main()
> {
> cout << "Hello World\n";

'cout' is in namespace.

You can

std::cout << "Hello World" << std::endl;

or

using namespace std;
cout << "Hello World" << endl;

The 'endl' adds a newline and flushes the output stream, i.e.

cout << endl;

does the same as

cout << "\n" << flush;

In practice you won't see a difference from not flushing. But in theory,
without it you could end up not seeing any of your output. Besides, it's bad
manners to not flush after you've done your thing.


>
> return (0);

This isn't necessary. 'main' returns 0 by default.

> }

[snip]
> 4530: C++ exception handler used, but unwind semantics are not enabled.
> Specify
> /EHsc

[snip]
>
> And what's this complaint about the exception handler?

In order to make that compiler compile C++, and not a language just resembling
C++, you have to add a lot of options. This is not unique to Visual C++,
though, it's just about the same with most so called C++ compilers: they don't
compile C++ by default. I use a batch file for building small test programs:


V:\> which msvc.bat
C:\Program Files\@commands\msvc.bat

V:\> type "C:\Program Files\@commands\msvc.bat"
@echo off
if "%*"=="--version" (
cl 2>&1
) else (
cl /nologo /GX /GR /Zc:forScope,wchar_t /W4 %*
)

V:\> _


Cheers, & hth.,

- Alf
From: Larry Lindstrom on
Alf P. Steinbach wrote:
> * Larry Lindstrom:

<Snip >
> 'cout' is in namespace.
>
> You can
>
> std::cout << "Hello World" << std::endl;
>
> or
>
> using namespace std;
> cout << "Hello World" << endl;

Thanks Alf:

GAAAK I KNOW THAT!

Jeeze, this post should have been named "C++ for Morons",
or "C++ for imbeciles", or idiots, or, what's the dumbest?

I wish I could say that was the first time I've made
that mistake, but I'd be lying.

Thanks for pointing that out to me.

Larry