Link error in minGW (seems libstdc++.a is not in the search path)

Discussion in 'C++' started by ddh, Jan 13, 2006.

  1. ddh

    ddh Guest

    Hi,

    I download mingw in my system(XP SP2), and extract them in
    c:\mingw\gcc, so the directories looks like: c:\mingw\gcc\bin,
    c:\mingw\gcc\include ..., and I added c:\mingw\gcc\bin in my PATH env.

    It is OK for compiling .c code, but when compiling c++ code, some
    error will occur.

    my cpp file:

    --- tmp.cpp ---
    #include <iostream>

    int main()
    {
    std::cout << "Hello, world!" << std::endl;
    return 0;
    }


    And the command line is :
    gcc -O2 -o tmp tmp.cpp


    It output:

    C:\DOCUME~1\user\LOCALS~1\Temp/ccYJbaaa.o(.text+0x1b):tmp.cpp:
    undefined refe
    rence to `std::cout'
    C:\DOCUME~1\user\LOCALS~1\Temp/ccYJbaaa.o(.text+0x29):tmp.cpp:
    undefined refe
    rence to `std::basic_ostream<char, std::char_traits<char> >&
    std::eek:perator<< <st
    d::char_traits<char> >(std::basic_ostream<char, std::char_traits<char>
    >&, char

    const*)'
    C:\DOCUME~1\user\LOCALS~1\Temp/ccYJbaaa.o(.text+0x31):tmp.cpp:
    undefined refe
    rence to `std::basic_ostream<char, std::char_traits<char> >&
    std::endl<char, std
    ::char_traits<char> >(std::basic_ostream<char, std::char_traits<char>
    >&)'

    C:\DOCUME~1\user\LOCALS~1\Temp/ccYJbaaa.o(.text+0x7c):tmp.cpp:
    undefined refe
    rence to `std::ios_base::Init::Init()'
    C:\DOCUME~1\user\LOCALS~1\Temp/ccYJbaaa.o(.text+0x98):tmp.cpp:
    undefined refe
    rence to `std::ios_base::Init::~Init()'
    collect2: ld returned 1 exit status



    But if the command line is:
    gcc -O2 -o tmp tmp.cpp c:\mingw\gcc\lib\libstdc++.a

    Then it will be OK.

    So I want to know how to set the envionment so that I can use the
    former command line to compile c++ code.

    Thank you
     
    ddh, Jan 13, 2006
    #1
    1. Advertising

  2. * ddh:
    > ...


    1) Use g++, not gcc, for C++ code.
    2) In future, please post to appropriate tool-specific group,
    since this group is concerned with the C++ _language_.

    Thank you,

    - 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, Jan 13, 2006
    #2
    1. Advertising

  3. ddh

    ddh Guest

    Thank you very much. It work.

    I am sorry for posting it here.


    Alf P. Steinbach wrote:
    > * ddh:
    > > ...

    >
    > 1) Use g++, not gcc, for C++ code.
    > 2) In future, please post to appropriate tool-specific group,
    > since this group is concerned with the C++ _language_.
    >
    > Thank you,
    >
    > - 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?
     
    ddh, Jan 16, 2006
    #3
    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. Replies:
    4
    Views:
    6,708
    Victor Bazarov
    Jul 16, 2004
  2. Sam Smith
    Replies:
    0
    Views:
    1,203
    Sam Smith
    Oct 18, 2004
  3. Doctor Bones

    libstdc runtime error on Unix box

    Doctor Bones, Oct 21, 2004, in forum: C++
    Replies:
    1
    Views:
    630
    Victor Bazarov
    Oct 21, 2004
  4. Alexander Dong Back Kim

    how to use libstdc++.so.5 instead of libstdc++.so.6

    Alexander Dong Back Kim, Sep 30, 2008, in forum: C++
    Replies:
    1
    Views:
    801
  5. xeno fears
    Replies:
    1
    Views:
    513
    Martin v. Löwis
    Oct 4, 2009
Loading...

Share This Page