当我尝试编译下面的代码时(在 Qt 4.8 中使用 llvm-g++-4.2 (GCC) 4.2.1),我收到以下错误:
../GLWidget.cpp:24: instantiated from here
../GLWidget.cpp:24: error: explicit instantiation of 'std::basic_ostream<_CharT, _Traits>& std::operator<<(std::basic_ostream<_CharT, _Traits>&, const std::basic_string<_CharT, _Traits, _Alloc>&) [with _CharT = char, _Traits = std::char_traits<char>, _Alloc = std::allocator<char>]' but no definition available
Run Code Online (Sandbox Code Playgroud)
这个错误是什么意思,我应该怎么做才能修复它?
源代码:
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
void testOStream(){
filebuf fb;
fb.open ("test.txt",ios::out);
std::ostream os(&fb);
std::string test("test");
os << test; // This line has the problem
fb.close();
}
Run Code Online (Sandbox Code Playgroud)
正如 @ChadCambell 指出的,问题是 Qt 4.8 使用 -mmacosx-version-min=10.5,但应该是 -mmacosx-version-min=10.7
我在这里找到了该问题的更多使用信息:
http://qt-project.org/forums/viewthread/19106/P15
更新到Qt 5.0也解决了这个问题