c++ problem vith gcc
  • Order of the Butterfly
    Order of the Butterfly
    maurensen
    Posts: 358 from 2003/10/3
    From: Padova - Italy
    I have a little stupid problem using gcc under MOS SDK in c++ mode.
    Here a piece of the file:
    -----------------------------------------------------

    include <iostream.h>

    // simple oo example

    class animal {
    int legs; // private
    public:
    animal(void); // costruttore
    ~animal(void); // distruttore
    void animal::putlegs(int legs); // prototipi
    void animal::putlegs(void); // polimorfismo...
    int animal::readlegs(void);
    };
    animal::animal(void) {
    cout << "Amimal initialized\n";
    legs=0;
    }

    ... and so on...
    ------------------------------------------------------
    The OO part seems to be complied OK but I get this nasty error message
    if I try to use cin/cout functions:

    /t/ccjnK8bm.o: In function `animal::animal(void)':
    /t/ccjnK8bm.o(.text+0x22): undefined reference to `cout'
    /t/ccjnK8bm.o(.text+0x26): undefined reference to `cout'
    /t/ccjnK8bm.o(.text+0x30): undefined reference to `ostream::operator<<(char const *)'
    collect2: ld returned 1 exit status

    What I'm doing wrong? Why I am not able to use cin/cout functions??
    Thanx 4 replying this stupid question but I'd really like to learn c++!!

    P.S.:Ah, I'm forgetting this little piece of code is inspired by the little
    Fabio Ciucci's(aka Randy/Ram Jam in the good 90's Amiga years) c++ course.
    Thanx RJ!!
    -------------------
  • »29.05.04 - 14:08
    Profile
  • Fab
  • MorphOS Developer
    Fab
    Posts: 1331 from 2003/6/16
    Just link with libstdc++ : -lstdc++

    And don't forget to put an extra space at the end of the line if you put -lstdc++ at the end.
  • »29.05.04 - 14:44
    Profile Visit Website
  • Order of the Butterfly
    Order of the Butterfly
    maurensen
    Posts: 358 from 2003/10/3
    From: Padova - Italy
    Thanx 4 your reply Fab!
    I've tried to compile with:

    gcc -noixemul -lstdc++ filename.cpp

    but I get always the error message.
    Is the command line ok or have I missed in the source
    file some #include ?
    Thanx a lot & ciao!
    -------------------
  • »31.05.04 - 14:14
    Profile
  • Leo
  • Order of the Butterfly
    Order of the Butterfly
    Leo
    Posts: 419 from 2003/8/18
    try to add the line:
    using namespace std;

    Leo.
    Nothing hurts a project more than developers not taking the time to let their community know what is going on.
  • »31.05.04 - 15:55
    Profile Visit Website
  • Fab
  • MorphOS Developer
    Fab
    Posts: 1331 from 2003/6/16
    try using g++ instead of gcc.
  • »31.05.04 - 16:26
    Profile Visit Website
  • Order of the Butterfly
    Order of the Butterfly
    maurensen
    Posts: 358 from 2003/10/3
    From: Padova - Italy
    Hi,
    I've tried the clasue:
    using namespace std;
    + invoiking g++ but I get always the error.
    Bah, this gcc is too much "unix/style" for my experience.
    Gazillions of dir with header files, softlinks, obscure
    command line syntax... :-( Not very much Amiga style!
    If only I was able to start the old good HisoftC++ with the integrated IDE... But it only freeze my Peg at startup! Damnit!
    Any more suggestions please?
    -------------------
  • »01.06.04 - 14:20
    Profile
  • Yokemate of Keyboards
    Yokemate of Keyboards
    Zylesea
    Posts: 2057 from 2003/6/4
    g++ within the sdk is broken. Some links are missing. Get the proper archive from Cisc (? or whoever it was).

    It would be great if the sdk would be updated...
    --
    http://via.bckrs.de

    Whenever you're sad just remember the world is 4.543 billion years old and you somehow managed to exist at the same time as David Bowie.
    ...and Matthias , my friend - RIP
  • »01.06.04 - 14:33
    Profile Visit Website
  • Order of the Butterfly
    Order of the Butterfly
    dholm
    Posts: 296 from 2003/9/1
    From: Malmo, Sweden
    Example:
    #include <iostream> // .h is deprecated in the current C++ standard
    using namespace std; // otherwise you will have to prefix calls to the std lib by 'std::'

    int main(void) {
    cout << "Test" << endl;
    return 0;
    }

    The g++ that comes with the SDK should work for this simple code. AFAIK the biggest problems are with templates.
    CISC's GCC can be fetched from here: http://www.morphos.org/meanmachine/files/gcc-2.95.3-bin.tar.bz2
    Keep everything from the current SDK and only replace g++, cc1plus and libstdc++ wit hthe files from CISC's archive. Disabling the memory resident GCC also help resolve some problems.
  • »01.06.04 - 14:58
    Profile Visit Website
  • Order of the Butterfly
    Order of the Butterfly
    maurensen
    Posts: 358 from 2003/10/3
    From: Padova - Italy
    @dholm
    Like U've suggested I've downloaded the fixed version of CISC's GCC and replaced the 3 files as satated in your post.
    Then I've launched g++ with my c++ code and i've crossed my fingers and... bang, finally it worked!
    Now I can compile & run my c++ killer application, an higly OO program that displays "hello world"!! :-)
    Dholm, thanx to your precious tips AFAIK my SDK is patched and working.
    -------------------------------
    (Here I'd like to be able to put many dancing bananas to express my happiness! :-))
    --------------------------------
    Again, many Thanx to dholm and to other nice guys that have tried to help me.
    Aloha.
    -------------------
  • »04.06.04 - 14:38
    Profile