【问题标题】:clang 3.4.1 no member named 'to_string' in namespace 'std'clang 3.4.1 在命名空间“std”中没有名为“to_string”的成员
【发布时间】:2014-09-26 04:29:28
【问题描述】:

我已经尝试了几个小时让 c++11、llvm/clang 和 netbeans 在 Windows 上工作。我几乎被困在这里。我无法看到 to_string 方法。在深入研究 basic_string 头文件后,我注意到在定义 to_string 之前有一些#ifdefs

#if ((__cplusplus >= 201103L) && defined(_GLIBCXX_USE_C99) \
     && !defined(_GLIBCXX_HAVE_BROKEN_VSWPRINTF))

在 Netbeans 中,我可以控制单击 _GLIBCXX_HAVE_BROKEN_VSWPRINTF 并注意到它定义为 1,并且控制单击不适用于 __cplusplus 和 _GLIBCXX_USE_C99,所以我假设它们未定义。

有谁知道如何解决这个问题?

如果有帮助,这里还有构建信息和源代码。

clang++ -v   -c -g -w -I../SFML/include -I../SFML/src -I../boostInclude -I/C\MinGW\lib\gcc\mingw32\4.8.1\include -I/C\MinGW\lib\gcc\mingw32\4.8.1\include-fixed -std=c++11 -MMD -MP -MF "build/Debug/CLang-Windows/System/SPString.o.d" -o build/Debug/CLang-Windows/System/SPString.o System/SPString.cpp
clang version 3.4.1 (207424)
Target: i686-pc-mingw32
Thread model: posix
Selected GCC installation: 
 "c:\Program Files (x86)\LLVM\bin\clang++.exe" -cc1 -triple i686-pc-mingw32 -S -disable-free -main-file-name SPString.cpp -mrelocation-model static -mdisable-fp-elim -fmath-errno -mconstructor-aliases -target-cpu pentium4 -v -g -coverage-file "C:\\Users\\IZACK_~1\\AppData\\Local\\Temp\\SPString-929e91.s" -resource-dir "c:\\Program Files (x86)\\LLVM\\bin\\..\\lib\\clang\\3.4.1" -dependency-file build/Debug/CLang-Windows/System/SPString.o.d -MT build/Debug/CLang-Windows/System/SPString.o -MP -I ../SFML/include -I ../SFML/src -I ../boostInclude -I C:/MinGW/msys/1.0/CMinGWlibgccmingw324.8.1include -I C:/MinGW/msys/1.0/CMinGWlibgccmingw324.8.1include-fixed -w -std=c++11 -fdeprecated-macro -fno-dwarf-directory-asm -fdebug-compilation-dir "C:\\SynapseCpp\\SynapseCore" -ferror-limit 19 -fmessage-length 0 -mstackrealign -fno-use-cxa-atexit -fobjc-runtime=gcc -fcxx-exceptions -fexceptions -fdiagnostics-show-option -vectorize-slp -o "C:\\Users\\IZACK_~1\\AppData\\Local\\Temp\\SPString-929e91.s" -x c++ System/SPString.cpp
clang -cc1 version 3.4.1 based upon LLVM 3.4.1-rc2 default target i686-pc-mingw32
ignoring nonexistent directory "C:/MinGW/msys/1.0/CMinGWlibgccmingw324.8.1include"
... bunch of irrelevant 'nonexistent directory' ...
ignoring duplicate directory "/mingw/include"
#include "..." search starts here:
#include <...> search starts here:
 ../SFML/include
 ../SFML/src
 ../boostInclude
 c:/MinGW/lib/gcc/mingw32/4.8.1/include/c++
 c:/MinGW/lib/gcc/mingw32/4.8.1/include/c++/mingw32
 c:/MinGW/lib/gcc/mingw32/4.8.1/include/c++/backward
 c:\Program Files (x86)\LLVM\bin\..\lib\clang\3.4.1\include
 c:\Program Files (x86)\LLVM\bin\..\lib\clang\3.4.1\../../../include
 /mingw/include
End of search list.
System/SPString.cpp:14:20: error: no member named 'to_string' in namespace 'std'
    string += std::to_string(right);
              ~~~~~^
System/SPString.cpp:21:20: error: no member named 'to_string' in namespace 'std'
    string += std::to_string(right);
              ~~~~~^
2 errors generated.

这是源代码:

#include "SPString.h"
#include <string>

sf::String& operator +=(const sf::String& left, int right)
{
    sf::String string = left;
    string += std::to_string(right);
    return string;
}

sf::String& operator +(const sf::String& left, int right)
{
    sf::String string = left;
    string += std::to_string(right);

    return string;
}

【问题讨论】:

  • 我记得这是由于 MinGW32 中的一个已知错误,它应该在 64 位版本中修复,但在 32 位版本中没有。请参阅stackoverflow.com/questions/12975341/… 了解更多信息。
  • 我确实在这里看到了错误:gcc.gnu.org/bugzilla/show_bug.cgi?id=52015,但我认为这不是问题,因为错误被标记为“已解决”。无论如何,我应用了该堆栈溢出问题中链接的补丁,但它似乎没有任何效果:/

标签: windows c++11 netbeans mingw clang


【解决方案1】:

我对你的 sf 类了解不多,但这里有一个可能的解决方法:

#include "SPString.h"
#include <string>
#include <sstream>

sf::String& operator +=(const sf::String& left, int right)
{
     std::stringstream stream;
     stream << right;

     sf::String string = left;
     string += stream.str(); 
     return string;
}

【讨论】:

    猜你喜欢
    • 2018-11-20
    • 2017-02-13
    • 2012-06-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多