简体   繁体   English

gstream中的fstream链接错误与-std = gnu ++ 0x

[英]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. 我在Windows上的tdm-mingw g ++ 4.4.0中有一个使用-std = gnu ++ 0x参数构建的应用程序。

It is using an ofstream object and when I build, it gives the following linking error: 它正在使用ofstream对象,当我构建时,它会给出以下链接错误:

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. 这是唯一的错误,尝试与-lstdc ++链接并没有帮助。 Has someone experienced this before? 以前有人经历过这个吗? Can I get any suggestions? 我可以得到任何建议吗?

Edit: I'm creating an ofstream object like this: 编辑:我正在创建一个像这样的ofstream对象:

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. 如果这不起作用,请发布导致问题的代码。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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