#32 Undefind reference to ...

Eric Friedman

Running "gcc -o test.exe gcc test.cpp" on a VERY
simple program:

// Test.cpp
#include <iostream>

void main()
std::cout << "Hello, world." << std::endl;
// End Test.cpp

causes the following errors:

(.text+0x1f):test.cpp: undefined reference to `endl
(ostream &)'
(.text+0x2c):test.cpp: undefined reference to
(.text+0x32):test.cpp: undefined reference to
`ostream::operator<<(char const *)'

What is the problem? I am relatively new to GCC, but
I have installed all the all the most up-to-date
parts. I also have Visual Studio 6 w/ Service Pack 5
installed. Before installing Service Pack 5, I did
not have any such problems. My only guess is that
there are incompatibiltiesbetween MinGW and libraries
installed by SP5? Can anyone confirm? And if this is
indeed a problem, when will a patch be made available?

Eric Friedman


  • Colin Peters
    Colin Peters

    Logged In: YES

    Looks to me like this is simply a case of not linking the
    stdc++ library. Try adding -lstdc++ (or -lstdc++.dll for
    gcc 2.95.2-3) to your gcc command line and see if that
    fixes it.

    However, you say that you didn't have problems before SP5,
    so I guess you have probably been doing that all along
    right? (This is why it's a good idea to include actual
    command lines in bug reports when possible.)

    The other possibility I can think of is VC/SP5 having
    somehow managed to include a libstdc++.a that gcc is
    finding before the Mingw one, but that seems *highly*
    unlikely (IMHO).

    Colin Peters

  • Eric Friedman
    Eric Friedman

    Logged In: YES

    Oh man, I feel stupid :-P

    Like I said, I am rather new to GCC. I had a long vacation
    between the last time I compiled a program and now, and
    apparently I forgot about the -lstdc++ flag.

    The compile works fine now when I add the -lstdc++.dll
    flag. Problem resolved. I apologize for any commotion I
    may have created.

    Much thanks for your quick and helpful response,
    Eric Friedman

  • Logged In: YES

    You should use g++ to link C++ apps.

    • priority: 5 --> 1
    • assigned_to: nobody --> pfalcon
    • status: open --> closed-invalid