Hello world not working on Unix :(

Discussion in 'C++' started by Charles, Oct 6, 2005.

  1. Charles

    Charles Guest

    Hi guys,

    I've tried a hello world script:

    #include <iostream>

    int main() {
    using namespace std;

    cout << "Hello!\n";
    return 0;
    }

    But I've got an error message:

    gcc test.cpp
    /var/tmp//ccZLLi7M.o(.text+0xd): In function `std::__verify_grouping(char
    const*, unsigned int, std::string const&)':
    : undefined reference to `std::string::size() const'
    /var/tmp//ccZLLi7M.o(.text+0x60): In function `std::__verify_grouping(char
    const*, unsigned int, std::string const&)':
    : undefined reference to `std::string::eek:perator[](unsigned int) const'
    /var/tmp//ccZLLi7M.o(.text+0x9d): In function `std::__verify_grouping(char
    const*, unsigned int, std::string const&)':
    : undefined reference to `std::string::eek:perator[](unsigned int) const'
    /var/tmp//ccZLLi7M.o(.text+0xc8): In function `std::__verify_grouping(char
    const*, unsigned int, std::string const&)':
    : undefined reference to `std::string::eek:perator[](unsigned int) const'
    /var/tmp//ccZLLi7M.o(.text+0x121): In function `main':
    : undefined reference to `std::cout'
    /var/tmp//ccZLLi7M.o(.text+0x126): In function `main':
    : 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*)'
    /var/tmp//ccZLLi7M.o(.text+0x152): In function
    `__static_initialization_and_destruction_0(int, int)':
    : undefined reference to `std::ios_base::Init::Init()'
    /var/tmp//ccZLLi7M.o(.text+0x183): In function `__tcf_0':
    : undefined reference to `std::ios_base::Init::~Init()'
    /var/tmp//ccZLLi7M.o(.eh_frame+0x11): undefined reference to
    `__gxx_personality_v0'

    I'm on PC-BSD. Any idea?
    Thanks,

    Charles.

    --
    Using Opera's revolutionary e-mail client: http://www.opera.com/mail/
    Charles, Oct 6, 2005
    #1
    1. Advertising

  2. Charles

    Charles Guest

    Indeed! It's working fine now.
    Thank you Alf!

    On Fri, 07 Oct 2005 01:56:20 -0000, Alf P. Steinbach <>
    wrote:

    > * Charles:
    >> Hi guys,
    >>
    >> I've tried a hello world script:

    >
    > That's a C++ program. C++ programmers will be _very angry_ if you tell
    > them
    > that C++ is a scripting language. You have been Warned. ;-)
    >
    >
    >> #include <iostream>
    >>
    >> int main() {
    >> using namespace std;
    >>
    >> cout << "Hello!\n";
    >> return 0;
    >> }
    >>
    >> But I've got an error message:
    >>
    >> gcc test.cpp

    >
    > Use 'g++' instead of 'gcc'; 'g++' uses 'gcc' internally but in addition
    > instructs the linker to add necessary C++ libraries, which you're
    > lacking when
    > you use 'gcc' directly and not specifying them yourself.
    >
    > Next time, please ask in a compiler/system-specific group about such
    > questions, since this group is concerned only with the C++ _language_,
    > not the
    > tools (in general).
    >
    > Cheers,
    >
    > - Alf
    >




    --
    Using Opera's revolutionary e-mail client: http://www.opera.com/mail/
    Charles, Oct 7, 2005
    #2
    1. Advertising

  3. * Charles:
    > Hi guys,
    >
    > I've tried a hello world script:


    That's a C++ program. C++ programmers will be _very angry_ if you tell them
    that C++ is a scripting language. You have been Warned. ;-)


    > #include <iostream>
    >
    > int main() {
    > using namespace std;
    >
    > cout << "Hello!\n";
    > return 0;
    > }
    >
    > But I've got an error message:
    >
    > gcc test.cpp


    Use 'g++' instead of 'gcc'; 'g++' uses 'gcc' internally but in addition
    instructs the linker to add necessary C++ libraries, which you're lacking when
    you use 'gcc' directly and not specifying them yourself.

    Next time, please ask in a compiler/system-specific group about such
    questions, since this group is concerned only with the C++ _language_, not the
    tools (in general).

    Cheers,

    - Alf

    --
    A: Because it messes up the order in which people normally read text.
    Q: Why is it such a bad thing?
    A: Top-posting.
    Q: What is the most annoying thing on usenet and in e-mail?
    Alf P. Steinbach, Oct 7, 2005
    #3

  4. > > That's a C++ program. C++ programmers will be _very angry_ if you tell




    Alf -


    C++ can be (and at times should be) called scripting language. Lot's
    of .bat scripts had, previously, been written by C/C++. Additionally,
    scripts written in C++ grammar run faster than any bash or others...


    Sometimes it is useful, and perhaps psychologically helpful, to admit
    your disgraceful defeat.
    puzzlecracker, Oct 7, 2005
    #4
  5. * puzzlecracker:
    >
    > > > That's a C++ program. C++ programmers will be _very angry_ if you tell

    >
    > C++ can be (and at times should be) called scripting language.


    That's right, e.g. <url: http://root.cern.ch/root/Cint.html>.

    In the same sense as a shoe heel can be called a hammer, in certain contexts.

    However, C++ is not a scripting language; for an explanation of "scripting
    language" see <url: http://en.wikipedia.org/wiki/Scripting_language> (which
    unfortunately does not link to CINT, but instead, misleadingly, to Ch).

    --
    A: Because it messes up the order in which people normally read text.
    Q: Why is it such a bad thing?
    A: Top-posting.
    Q: What is the most annoying thing on usenet and in e-mail?
    Alf P. Steinbach, Oct 7, 2005
    #5
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Matthew

    Unix, "hello world"

    Matthew, Jun 14, 2004, in forum: C++
    Replies:
    6
    Views:
    4,329
    markspace
    Jun 15, 2004
  2. vijay
    Replies:
    8
    Views:
    688
  3. Roy
    Replies:
    6
    Views:
    577
    Roedy Green
    Jan 7, 2008
  4. Larry
    Replies:
    27
    Views:
    407
    Michele Dondi
    Jan 25, 2005
  5. Admin

    "Hello World!" not working

    Admin, Sep 20, 2005, in forum: Perl Misc
    Replies:
    6
    Views:
    97
    Big and Blue
    Sep 21, 2005
Loading...

Share This Page