views:

406

answers:

1

Hello, I'm have an application built with the -std=gnu++0x parameter in tdm-mingw g++ 4.4.0 on windows.

It is using an ofstream object and when I build, it gives the following linking error:

c:\opt\Noddler/main_func.cpp:43: undefined reference to `std::basic_ofstream<char, std::char_traits<char> >::basic_ofstream(std::string const&, std::_Ios_Openmode)'

It builds properly when using the default older standard.

This is the only error, and trying to link with -lstdc++ doesn't help. Has someone experienced this before? Can I get any suggestions?

Edit: I'm creating an ofstream object like this:

std::string filename = string("noddler\\") + callobj.get_ucid() + "_" + callobj.gram_counter() + ".grxml";
ofstream grxml_file(string("C:\\CWorld\\Server\\Grammar\\") + filename);
...
grxml_file.close();

It is getting compiled fine, but not getting linked.

+3  A: 

I would guess that you have some code like this:

string fname = "foo.txt";
ifstream ifs( fname );

Try changing it to:

ifstream ifs( fname.c_str() );

This could happen if the header files you are using are somewhat out of whack with the libraries you are linking to. And if this doesn't work, post the code that causes the problem.

anon
Even if that change *does* work, this isn't a very satisfying solution, as it stands now. It amounts to saying that in order to build in C++0X mode, you shouldn't use the new C++0X feature. The actual solution probably involves getting command switches right on `g++`, or putting files in the right place.
Rob Kennedy
I think anyone building real solutions against the proposed C++0X standard is misguided. By all means build explorartory code against such things, but build real code against existing standards and iomplemntations that solidly support those standards.
anon
What new C++0x feature is this?
GMan
That solved it, Neil. Thanks. By the way, I'm only building exploratory code, but by now, we can expect most of the features to be finalized in the standard right? Would there be too many changes from what it is right now?
Sahasranaman MS
@GMan: http://en.wikipedia.org/wiki/C%2B%2B0xhttp://www.artima.com/cppsource/cpp0x.htmlhttp://gcc.gnu.org/projects/cxx0x.html
the_drow
Not to sound nit-picky but asking "what specific feature..." isn't usually best answered by referencing pages with lists of features.
GMan