简体   繁体   中英

fstream linking error in g++ with -std=gnu++0x

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM