Kind of a newbi question about gcc (I think)

Discussion in 'Linux - General discussion' started by Venaqua, Jun 19, 2008.

  1. Venaqua

    Venaqua Member

    Joined:
    Apr 13, 2008
    Messages:
    28
    Likes Received:
    0
    Trophy Points:
    11
    So I switch from Windows to Ubuntu about a month or two ago and I thought it would make sense to learn some programing so I'm trying to learn C++ and, of course my first program is a Hello World one named Hello.cpp. The book I'm learning from says to type at the command prompt ~$cc Hello.cpp to compile it in MS-DOS.

    So what I need to know is, for Linux would I type ~$gcc Hello.cpp. If not then what should I type and if so then why does this happen.

    In file included from /usr/include/c++/4.2/backward/iostream.h:31,
    from Hello.cpp:1:
    /usr/include/c++/4.2/backward/backward_warning.h:32:2: warning: #warning This file 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.
    /tmp/ccsOXpwT.o: In function `std::__verify_grouping(char const*, unsigned int, std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)':
    Hello.cpp:(.text+0xe): undefined reference to `std::basic_string<char, std::char_traits<char>, std::allocator<char> >::size() const'
    Hello.cpp:(.text+0x59): undefined reference to `std::basic_string<char, std::char_traits<char>, std::allocator<char> >::eek:perator[](unsigned int) const'
    Hello.cpp:(.text+0x97): undefined reference to `std::basic_string<char, std::char_traits<char>, std::allocator<char> >::eek:perator[](unsigned int) const'
    Hello.cpp:(.text+0xdf): undefined reference to `std::basic_string<char, std::char_traits<char>, std::allocator<char> >::eek:perator[](unsigned int) const'
    /tmp/ccsOXpwT.o: In function `main':
    Hello.cpp:(.text+0x128): undefined reference to `std::cout'
    Hello.cpp:(.text+0x12d): undefined reference to `std::basic_ostream<char, std::char_traits<char> >& std::eek:perator<< <std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*)'
    /tmp/ccsOXpwT.o: In function `__static_initialization_and_destruction_0(int, int)':
    Hello.cpp:(.text+0x15d): undefined reference to `std::ios_base::Init::Init()'
    /tmp/ccsOXpwT.o: In function `__tcf_0':
    Hello.cpp:(.text+0x1aa): undefined reference to `std::ios_base::Init::~Init()'
    /tmp/ccsOXpwT.o:(.eh_frame+0x11): undefined reference to `__gxx_personality_v0'
    collect2: ld returned 1 exit status

    After this happens I don't get a program or any thing else.Could somebody please tell me what this means.
    Also heres the program in case I made A mistake there (tho I don't think I did).

    #include <iostream.h>

    int main ()
    {
    cout<<"Hello, World\n";
    return 0;
    }

    If somebody could help me I would really appreciate.
     
  2. varnull

    varnull Guest

    Not the kind of help you will find on this site.. Think I'm about the only C programmer of any kind here ;) And it's years ago now.. haven't done any in ages.

    so.. you are working through Object-Oriented Programming in C++
    by Nicolai M. Josuttis eh? Not a bad book.. a little thin on the actual explanation.

    Code:
    #include <iostream>    // declarations for I/O
    
    int main()            // main function main()
    {
        /* print `Hello, World!' on standard output channel std::cout
         * followed by an endline (std::endl)
         */
        std::cout << "Hello, World!" << std::endl;
    }
    You are using an old/deprecated header..
    i.e <iostream.h> where you should be using <iostream> and from there on it all goes wrong... you should be able to work out from my code example you aren't actually generating anything, or outputting it to anywhere.
    When you have managed to actually compile it call the resulting file hello.c and you should be able to run it by making it executable and calling it by name XD
    For the compiler commands try the man page for whatever C compiler you are using. This should help ;) http://www.cyberciti.biz/faq/compiling-c-program-and-creating-executable-file/

    Lesson 1.. read the output from errors carefully ;) Have fun
     
    Last edited by a moderator: Jun 19, 2008
  3. Venaqua

    Venaqua Member

    Joined:
    Apr 13, 2008
    Messages:
    28
    Likes Received:
    0
    Trophy Points:
    11
    Thanks but I'm not reading Object-Oriented Programming in C++ by Nicolai M. Josuttis.
    I'm reading Teach Yourself C++ by Richard Riley.I copied the code out of that book to make sure my compiler worked. But apparently the code doesn't work. The copyright date on the book is 1999. Should I get A newer book.

    Anyways, I tried your code and got this

    /tmp/ccpC8w57.o: In function `std::__verify_grouping(char const*, unsigned int, std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)':
    Hello.cpp:(.text+0xe): undefined reference to `std::basic_string<char, std::char_traits<char>, std::allocator<char> >::size() const'
    Hello.cpp:(.text+0x59): undefined reference to `std::basic_string<char, std::char_traits<char>, std::allocator<char> >::eek:perator[](unsigned int) const'
    Hello.cpp:(.text+0x97): undefined reference to `std::basic_string<char, std::char_traits<char>, std::allocator<char> >::eek:perator[](unsigned int) const'
    Hello.cpp:(.text+0xdf): undefined reference to `std::basic_string<char, std::char_traits<char>, std::allocator<char> >::eek:perator[](unsigned int) const'
    /tmp/ccpC8w57.o: In function `main':
    Hello.cpp:(.text+0x128): undefined reference to `std::cout'
    Hello.cpp:(.text+0x12d): undefined reference to `std::basic_ostream<char, std::char_traits<char> >& std::eek:perator<< <std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*)'
    Hello.cpp:(.text+0x135): undefined reference to `std::basic_ostream<char, std::char_traits<char> >& std::endl<char, std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&)'
    Hello.cpp:(.text+0x13d): undefined reference to `std::basic_ostream<char, std::char_traits<char> >::eek:perator<<(std::basic_ostream<char, std::char_traits<char> >& (*)(std::basic_ostream<char, std::char_traits<char> >&))'
    /tmp/ccpC8w57.o: In function `__static_initialization_and_destruction_0(int, int)':
    Hello.cpp:(.text+0x16d): undefined reference to `std::ios_base::Init::Init()'
    /tmp/ccpC8w57.o: In function `__tcf_0':
    Hello.cpp:(.text+0x1ba): undefined reference to `std::ios_base::Init::~Init()'
    /tmp/ccpC8w57.o:(.eh_frame+0x11): undefined reference to `__gxx_personality_v0'
    collect2: ld returned 1 exit status

    I don't know what that means. But I followed the link you gave and got it to work. But do you think my book is to old to learn out of.
     
  4. varnull

    varnull Guest

    That is a long time ago. It's about the time I last did any C coding ;)

    Obviously the compilers have moved on from then, but in theory it should all work.

    I think you really need up to date and relevant help... and I can't think of any nicer people to help you out than at http://www.jharbour.com/forum

    Otherwise.. just read and read. The linux compiler documentation is huge, and doesn't always follow what you will find in books which always seem to have been written for windows/dos based compilers these days.

    Good Luck..
     
  5. OzMick

    OzMick Guest

    I can't help much either. Always preferred pure C myself, never bothered with remembering much while learning C++. In C at least the following works, but being C probably means dick to you.

    #include <stdio.h>

    int main (int argc, char** argv) {
    printf("Hello world\n");
    return 0;
    }

    There are loads of tutorials on the net, you should be able to find some good references without too much trouble. The language shouldn't have changed too significantly in the last 10 years, but could well have. C at least has such a small command set that 20 year old K&R ANSI C textbooks are still perfectly good.
     
  6. varnull

    varnull Guest

    Went playing with a pure unix system for work today.... I think you are lacking some of the C dev libs, which is why all the errors.
    Ubuntu is sorely lacking in build/compile tools.. which I forgot all about. Try installing the debian build-essentials package and trying again ;)
     
  7. OzMick

    OzMick Guest

    Varnull is probably right, Ubuntu is pretty useless in that respect. I remember the nightmare I went through to compile my network card driver so that I could just connect to the net a year or so ago. They stick you in a really dumb catch 22 - to compile anything you need to download libraries, but to download libraries I needed to be able to compile.

    I think the live CD does have the required packages activated though, so you can build things before rebooting into your system and just transfer it across on a memory stick. But then you run into the same problem a few months later when the next kernel update rolls around and you haven't got the development packages installed...
     
  8. Venaqua

    Venaqua Member

    Joined:
    Apr 13, 2008
    Messages:
    28
    Likes Received:
    0
    Trophy Points:
    11
    Wait I'm a little confused. Should I use an Ubuntu live cd and but the build-essential package on usb stick. Or should I get a Debian live cd and then put their build-essential package on a usb stick. Or is there some were I can download the package.

    Thanks for being so helpful guys.
     
  9. OzMick

    OzMick Guest

    No, I was just telling a story of my experience with Ubuntu. Just use synaptic to install that package into your existing Ubuntu install and (hopefully) it will all work.

    Sorry for any confusion there, your situation is just another example of why people don't tend to stay using Ubuntu for too long - it is easy for noobs to get started on, but the moment you want to do anything meaningful beyond just installing and using provided packages you seem to have to fight 10x harder than you would on any other distro.
     
  10. OzMick

    OzMick Guest

    Just got the same messages when using the same source. Try using g++ instead of gcc...

    Sure does pay to google, "c++ hello world linux" makes the solution a giveaway.

    Edited because I probably sounded like an ass.
     
    Last edited by a moderator: Jun 20, 2008
  11. varnull

    varnull Guest

    Oops **blushes**.. missed that one. i use a different compiler in a development environment separated from the main os (because I build platform independent IF I ever need to actually build anything so I can swap it around different machines)

    I'm a bit distracted today.. lots going on around me.
     
    Last edited by a moderator: Jun 20, 2008
  12. Venaqua

    Venaqua Member

    Joined:
    Apr 13, 2008
    Messages:
    28
    Likes Received:
    0
    Trophy Points:
    11
    lol you did kind of sound like an ass .

    I had the build-essentials package installed before I started. Should I try to find a debian build-essentials package and install that.

    Also I tried using g++ instead gcc and it pretty much worked except that I had to add namespace std; to the code. Is that kind of new thing.
     
  13. Brookscbg

    Brookscbg Guest

    Linux is not a user friendly OS at all but it's very often used in oop oriented languages.
     
  14. varnull

    varnull Guest

    Don't know where you get the idea it isn't user friendly.. It's the M$ stuff that is designed to lock the user out, not the open source OS.

    Now about this compile error.. Better to look at the man page for the g++ compiler that is specific to your system. Every release has different requirements. I have a feeling there are still some dependencies missing.. such as g++-dev and quite possibly the linux-kernal-headers.

    That is the kind of problem you can get when you are trying to build what is effectively alien code against your normal system libraries.

    Maybe a good read of the LFS guides and homepage will solve all the problems and show you how to create a safe, and system independent build environment.
     
    Last edited by a moderator: Jun 25, 2008
  15. OzMick

    OzMick Guest

    Have you actually used Linux or are you just spouting the same uninformed crap that MS shills have been for years? If you're just trolling, go back under your bridge or you'll be put there by one of the moderators.
     
  16. creaky

    creaky Moderator Staff Member

    Joined:
    Jan 14, 2005
    Messages:
    27,900
    Likes Received:
    1
    Trophy Points:
    96
    These days it is actually very user friendly. And i'll ask you in a friendly manner to remove that link from your signature...
     
  17. varnull

    varnull Guest

    Under the bridge indeed.. I like that image ;)

    "I went with Fista down under the bridge.. I went in a child, and came out a sore fool" hahahaha.

    FYI.. the bloody n00buntu repositories are broken again!! (and broken so well that poor Grace had a brainstorm, segfaulted and totally corrupted the /var/lib/dpkg/status file... which believe, you never ever want to have to edit manually.. all 32,000 lines of it.)
    Lesson learned.. on n00b don't ever apt-get dist-upgrade without backing that damn file up somewhere else first.
    I have put some dents in the walls of the house this evening.. and probably in my head as well..grrrrr.. arch here we come.[​IMG]
     
    Last edited by a moderator: Jun 25, 2008
  18. OzMick

    OzMick Guest

    If you're giving Arch a crack, a new base install disc was released just the other day. Doesn't mean too much if you're doing an FTP install (recommended), but there have been a couple of rearrangements to the repository categories over the past 6 months and it is running the latest kernel on the disc at least, so no reason not to use the latest.

    Same rules as "emerge -U world" apply to "pacman -Syu". I think the best thing to do is either sync every week or never, you'd know the drill from Gentoo/Sabayon.

    It isn't an option by default, but a few people link /var/cache/pacman/pkg to a separate partition, that way you can share downloaded packages between machines nicely or not lose them if you manage to obliterate your root partition.
     
  19. varnull

    varnull Guest

    Cheers for that... I will give it a go later, or over the weekend. I just needed it up and running last night to finish a rush job, so it ended up being lenny ;)
     
  20. ktulu14

    ktulu14 Regular member

    Joined:
    Dec 8, 2004
    Messages:
    143
    Likes Received:
    0
    Trophy Points:
    26
    Nowt wrong with lenny, runs on my main box as sweet as a dream. I will use it when i get round to building a home server (too much going on to sort out the finer points of that yet i.e. getting hdd's).
     

Share This Page