Re: C++ Compiling Problems

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Sun, May 22, 2005 at 02:48:20PM +0200, Coert Waagmeester wrote:
> I've started learning C++. (Should I first learn C ?)

You can learn C++ directly, and if you're interested in learning good C++,
there's some reasons to suggest doing it that way. C is a very elegant and
uncomplicated language. C++ is a different story.

However, if you're basically new to programming, your life will probably be
easier if you *start* with working with an object oriented appoach to
programming. A *lot* of C++ code out there is actually an ugly mix of core C
with some C++ constructs glommed on. Modern C++ shouldn't be like that, and
in fact all of this ...

> I have an eBook from SAMS Teach yourself C++ in 21 days
> When I compiled their Hello World example:
> 
> 1: #include <iostream.h>
> 2:
> 3: int main()
> 4: {
> 5:    cout << "Hello World!\n";
> 6:        return 0;
> 7: } 
> 
> g++ came back with:
> In file included from /usr/lib/gcc/i386-redhat-linux/3.4.2/../../../../include/c++/3.4.2/backward/iostream.h:31,from hello.cpp:1:
> /usr/lib/gcc/i386-redhat-linux/3.4.2/../../../../include/c++/3.4.2/backward/backward_warning.h:32:2: warning:
> #warning Thisfile includes at least one deprecated or antiquated header. Please consider using one of the 32 headers
> found in section 17.4.1.2 of the C++ standard. Examples include substituting the <X> header for the <X.h> header for C++ includes,
> or <iostream> instead of the deprecated header <iostream.h>. To disable this warning use -Wno-deprecated.

... is *exactly* that issue -- iostream.h is the older, more-C-like header
file, and instead, you want the one called just iostream, with no extension.

Basically, sounds like you need a newer book.

I've checked out many of the C++ books out there, and the one I recommend 
above all others is Object-Oriented Programming in C++ (4th Edition) by
Robert Lafore. (The current edition is also from SAMS -- older ones were
published by The Waite Group.)

It's *really* well written, and perhaps more importantly, very well
structured for learning.


> But the a.out file that gets created, does work, and
> gives Hello World! on the console.
> Should I worry about this warning?

Yes. :)

> They also say in the eBook that I still need to run the 'linker' on the file that is compiled,
> but the a.out file already works? When I ran 'ld a.out' it did not work anymore.
> Why do I not need to run the linker?

Because you're using GCC, which also includes a linker, and in fact will
default to doing the linking stage unless you use the -c flag to stop it.

And even cooler, under GNU make (which you have in Fedora Core), if you have
a program named "helloworld.cpp", you can just type "make helloworld" (from
a prompt in the same directory), and it'll automatically call gcc with the
right flags to generate an executable named "helloworld". (And will print
out what it's doing.)

PS: if you want a book on C instead of C++, don't bother with anything but
the original book by the language's creators: C Programming Language by
Brian Kernighan and Dennis Ritchie. As I said before, C is an elegant and
small language, and this book is all you need. (Although you may also want
to pick up The UNIX Programming Environment by Kernighan and Rob Pike.)

-- 
Matthew Miller           mattdm@xxxxxxxxxx        <http://www.mattdm.org/>
Boston University Linux      ------>                <http://linux.bu.edu/>
Current office temperature: 73 degrees Fahrenheit.


[Index of Archives]     [Current Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Yosemite News]     [Yosemite Photos]     [KDE Users]     [Fedora Tools]     [Fedora Docs]

  Powered by Linux