Thread: undefined reference to `std::basic_string

  1. #1
    Registered User
    Join Date
    Dec 2003
    Posts
    20

    undefined reference to `std::basic_string

    I get this big error while trying to compile a simple C program

    under Cygwin


    Code:
    $ gcc FileClass2.cpp
    In file included from FileClass2.cpp:3:
    require.h:58:26: warning: no newline at end of file
    /cygdrive/c/DOKUME~1/KHAJA~1.MOH/LOKALE~1/Temp/ccI3GSd5.o:FileClass2.cpp:(.text+
    0xd): undefined reference to `std::basic_string<char, std::char_traits<char>, st
    d::allocator<char> >::size() const'
    /cygdrive/c/DOKUME~1/KHAJA~1.MOH/LOKALE~1/Temp/ccI3GSd5.o:FileClass2.cpp:(.text+
    0x60): undefined reference to `std::basic_string<char, std::char_traits<char>, s
    td::allocator<char> >::operator[](unsigned int) const'
    /cygdrive/c/DOKUME~1/KHAJA~1.MOH/LOKALE~1/Temp/ccI3GSd5.o:FileClass2.cpp:(.text+
    0x9f): undefined reference to `std::basic_string<char, std::char_traits<char>, s
    td::allocator<char> >::operator[](unsigned int) const'
    /cygdrive/c/DOKUME~1/KHAJA~1.MOH/LOKALE~1/Temp/ccI3GSd5.o:FileClass2.cpp:(.text+
    0xce): undefined reference to `std::basic_string<char, std::char_traits<char>, s
    td::allocator<char> >::operator[](unsigned int) const'
    /cygdrive/c/DOKUME~1/KHAJA~1.MOH/LOKALE~1/Temp/ccI3GSd5.o:FileClass2.cpp:(.text+
    0x205): undefined reference to `___gxx_personality_sj0'
    collect2: ld returned 1 exit status
    Last edited by Salem; 09-04-2006 at 05:32 AM. Reason: code tagged - please learn to use them!

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,412
    You have a C++ program, not a C program.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Registered User
    Join Date
    Dec 2003
    Posts
    20

    undefined reference to `std::basic_string

    oh sorry a CPP program

    is there any solution for this

    i know something to do with linker

    but not able to sort it out

  4. #4
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Stop compiling as C, and move to the C++ board. You can't compile C++ on a C compiler.


    Quzah.
    Hope is the first step on the road to disappointment.

  5. #5
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,656
    Moved to C++ board.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  6. #6
    Registered User
    Join Date
    Mar 2009
    Posts
    2

    Ashish Patel

    just compile with g++ compiler

    g++ -c <cpp-file>
    g++ -o <bin-file> <obj-file>

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Getting an error with OpenGL: collect2: ld returned 1 exit status
    By Lorgon Jortle in forum C++ Programming
    Replies: 6
    Last Post: 05-08-2009, 08:18 PM
  2. Undefined Reference Compiling Error
    By AlakaAlaki in forum C++ Programming
    Replies: 1
    Last Post: 06-27-2008, 11:45 AM
  3. Screwy Linker Error - VC2005
    By Tonto in forum C++ Programming
    Replies: 5
    Last Post: 06-19-2007, 02:39 PM
  4. C OpenGL Compiler Error?
    By Matt3000 in forum C Programming
    Replies: 12
    Last Post: 07-07-2006, 04:42 PM
  5. c++ linking problem for x11
    By kron in forum Linux Programming
    Replies: 1
    Last Post: 11-19-2004, 10:18 AM