fstream.h 中的 STL 命名空间错误与 qmake/make.

STL Namespace Errors in fstream.h with qmake/make

本文关键字:qmake make 错误 命名空间 中的 STL fstream      更新时间:2023-10-16

我正在尝试以老派的方式编译我的 QT5 项目,使用qmake && make. 但是,我遇到了意外错误。 有~20个,但这里有一个样本(它们都是相似的(:

In file included from src/main.cc:18:
In file included from include/Ctx.h:7:
In file included from include/SrcFile.h:5:
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/fstream:268:9: error:
no template named 'has_facet'; did you mean
'::std::has_facet'?
if (has_facet<codecvt<char_type, char, state_...
^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/__locale:177:1: note:
'::std::has_facet' declared here
has_facet(const locale& __l)  _NOEXCEPT
^
In file included from src/main.cc:18:
In file included from include/Ctx.h:7:
In file included from include/SrcFile.h:5:
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/fstream:268:19: error:
no template named 'codecvt'; did you mean
'::std::codecvt'?
if (has_facet<codecvt<char_type, char, state_...
^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/__locale:817:86: note:
'::std::codecvt' declared here
...class _StateT> class _LIBCPP_TYPE_VIS_ONLY codecvt;
^
fatal error: too many errors emitted, stopping now
[-ferror-limit=]
20 errors generated.
make: *** [tmp/main.o] Error 1

下面是 SrcFile.h

#ifndef SRCFILE_H
#define SRCFILE_H
#include <string>
#include <fstream>
#include "SrcObj.h"

namespace oonalysis {
class SrcFile : public SrcObj
{
public:
SrcFile(const std::string& filename);
std::string get_text() const;
std::string present_name() const;
private:
std::filebuf* get_file();
std::string filename;
}; // class SrcFile
} // namespace oonalysis
#endif // SRCFILE_H

以下是生成的生成文件的可能部分

INCPATH       = -I. -Iinclude -I/usr/local/Cellar/qt/5.9.1/lib/QtWidgets.fram
ework/Headers -I/usr/local/Cellar/qt/5.9.1/lib/QtGui.framework/Headers -I/usr
/local/Cellar/qt/5.9.1/lib/QtCore.framework/Headers -I. -I/Applications/Xcode
.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.12.
sdk/System/Library/Frameworks/OpenGL.framework/Headers -I/Applications/Xcode.
app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.12.s
dk/System/Library/Frameworks/AGL.framework/Headers -I/usr/local/Cellar/qt/5.9
.1/mkspecs/macx-clang -F/usr/local/Cellar/qt/5.9.1/lib
CC            = /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang
CXX           = /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang++
CXXFLAGS      = -pipe -stdlib=libc++ -g -std=gnu++1y $(EXPORT_ARCH_ARGS) -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.12.sdk -mmacosx-version-min=10.10 -Wall -W -fPIC $(DEFINES)
tmp/srcfile.o: src/srcfile.cc include/SrcFile.h 
include/SrcObj.h 
include/oonalysis.h
$(CXX) -c $(CXXFLAGS) $(INCPATH) -o tmp/srcfile.o src/srcfile.cc

我是否配置错误? 有什么办法可以让我有两个 stl 版本漂浮?

这个问题并不直观。 在一个不相关的标头中,gui.h,我没有用结尾大括号关闭我的命名空间gui。 我通过注释掉#include <fstream>和编译来解决这个问题。 现在它工作正常。