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

D

ddh

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 said:
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 said:
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
 
A

Alf P. Steinbach

* 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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,050
Latest member
AngelS122

Latest Threads

Top