Problems with linking and std c++ library when using -mnocygwin

Markus Heiden markus@markusheiden.de
Mon Apr 3 22:55:00 GMT 2006


I have an c++ application which uses ifstream.close() like this:

----------
#include <string>
#include <iostream>
using namespace std;

void readMainConfig ()
{
  ifstream *config = new ifstream("x.cfg");
  ...
  config->close();
  delete config;
}
----------

cygwin can compile the .cpp files but when linking everything together, 
always "undefined reference" messages appear for the line with close():

----------
g++  -mno-cygwin -w -march=i686 -Dstricmp=strcasecmp -Dstrcmpi=strcasecmp -I"./someDir" 
 -c -o x1.o x1.cpp
...
g++ -mno-cygwin -fPIC -shared -o xxx_i686.dll  x1.o  x2.o  x3.o ... -lm

x1.o: In function `_Z14readMainConfigv':
x1.cpp:9: undefined reference to `std::basic_ifstream<char, 
std::char_traits<char> >::_close()'
----------

When I use the -O2 g++ option, things go worse. Then "new ifstream("x.cfg")" 
causes undefined references to _open(...).

Under linux everything compiles fine without any substantial change, just 
the compile & link flags are different.

I am using the most current version of all cygwin packages.
What am I doing wrong?
-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/x-pkcs7-signature
Size: 2800 bytes
Desc: not available
URL: <http://cygwin.com/pipermail/cygwin/attachments/20060403/c2512913/attachment.bin>


More information about the Cygwin mailing list