Announcement

Collapse
No announcement yet.

C++ std lib problem

Collapse
This topic is closed.
X
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    C++ std lib problem


    It's been a few years since I have programmed in C++. I'm starting
    to develop some programs in C++ and I can't get "Hello, World" working
    yet. It looks to me like 'cout' in the std library is not being found, even
    though I have it installed on the system.

    I'm using gcc version 3.4.6 and I have libstdc++5 and libstdc++6 installed.

    my program looks like this:


    // Builder.cc
    #include "Builder.h"

    Builder::Builder() {
    // cout << "Builder constructor\n" ;
    }


    // Builder.h
    #ifndef BUILDER_H
    #define BUILDER_H
    #endif

    class Builder {
    public:
    Builder();

    };



    // test.cc
    #include <iostream>

    using namespace std;

    #include "Builder.h"

    main() {
    Builder b = Builder();

    cout << "Hello\n";
    }


    # makefile

    Builder.o: Builder.cc
    gcc -c Builder.cc

    test.o: test.cc
    gcc -c test.cc

    test: test.o Builder.o
    gcc -o test Builder.o test.o

    clean:
    rm -rf *.o test



    When I compile and link, I get the following linking error message:

    gcc -c test.cc
    gcc -c Builder.cc
    gcc -o test Builder.o test.o
    test.o: In function `std::__verify_grouping(char const*, unsigned int, std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)':test.cc.text+0xd): undefined reference to `std::basic_string<char, std::char_traits<char>, std::allocator<char> >::size() const'
    :test.cc.text+0x64): undefined reference to `std::basic_string<char, std::char_traits<char>, std::allocator<char> >:perator&#91;](unsigned int) const'
    :test.cc.text+0xa4): undefined reference to `std::basic_string<char, std::char_traits<char>, std::allocator<char> >:perator&#91;](unsigned int) const'
    :test.cc.text+0xd3): undefined reference to `std::basic_string<char, std::char_traits<char>, std::allocator<char> >:perator&#91;](unsigned int) const'
    test.o: In function `main':test.cc.text+0x136): undefined reference to `std::cout'
    :test.cc.text+0x13b): undefined reference to `std::basic_ostream<char, std::char_traits<char> >& std:perator<< <std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*)'
    test.o: In function `__static_initialization_and_destruction_0(int, int)':test.cc.text+0x163): undefined reference to `std::ios_base::Init::Init()'
    test.o: In function `__tcf_0':test.cc.text+0x194): undefined reference to `std::ios_base::Init::~Init()'
    test.o.eh_frame+0x11): undefined reference to `__gxx_personality_v0'
    collect2: ld returned 1 exit status
    make: *** [test] Error 1



    Does anyone have any suggestions on how to fix my problem? Thank
    you in advance!!

    Jim Anderson

    #2
    Re: C++ std lib problem


    The solution on this problem was easy. I have to use g++, the
    C++ compiler, not gcc.

    Jim

    Comment

    Working...
    X