Re: C++ Compiling Problems

From: Matthew Miller (mattdm_at_mattdm.org)
Date: 05/22/05

  • Next message: Gregory P. Ennis: "Re: Compile Failure with fortune (missing recode.h)"
    Date: Sun, 22 May 2005 10:51:39 -0400
    To: For users of Fedora Core releases <fedora-list@redhat.com>
    
    

    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@mattdm.org        <http://www.mattdm.org/>
    Boston University Linux      ------>                <http://linux.bu.edu/>
    Current office temperature: 73 degrees Fahrenheit.
    -- 
    fedora-list mailing list
    fedora-list@redhat.com
    To unsubscribe: http://www.redhat.com/mailman/listinfo/fedora-list
    

  • Next message: Gregory P. Ennis: "Re: Compile Failure with fortune (missing recode.h)"

    Relevant Pages

    • Re: object system...
      ... for that you need machine language. ... isn't even as fast as other systems programming languages. ... Stroustrup's stated design goal was to enable ... all manner of elegance or abstraction can be sacrificed for speed, ...
      (comp.object)
    • Re: DirectX in HLA
      ... I guess that you have a great knowledge of DirectX ... > understanding by looking at them in assembly language... ... > actually represents, really, is a means to "undo" the OOP so ... > is NOT an "OOPL" (object-orientated programming language), ...
      (comp.lang.asm.x86)
    • Re: DirectX in HLA
      ... I guess that you have a great knowledge of DirectX ... > understanding by looking at them in assembly language... ... > actually represents, really, is a means to "undo" the OOP so ... > is NOT an "OOPL" (object-orientated programming language), ...
      (alt.lang.asm)
    • Re: LSP and subtype
      ... What is the class of problems solvable using UML? ... the language of physics cannot describe. ... whatever paradigm equivalent to 2GL/3GL ... there is still a great need for reuse and generic programming. ...
      (comp.object)
    • Re: Why C Is Not My Favourite Programming Language
      ... If you decide afterall that C programming is just not your thing you ... > C has no string type. ... > compiler take care of the rest. ... Why does any normal language ...
      (comp.lang.c)