首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >Clang似乎忽略了Mac操作系统下的C++版本(std=gnu++14和类似版本)。

Clang似乎忽略了Mac操作系统下的C++版本(std=gnu++14和类似版本)。
EN

Stack Overflow用户
提问于 2022-08-30 23:39:19
回答 2查看 215关注 0票数 -2

我正在MacOS11.6.8上开发,安装了Xcode 13.2.1 (但我正在开发VS代码中基于CMake的项目)。我对大量的构建错误感到困惑,例如:

代码语言:javascript
运行
复制
In file included from /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX12.1.sdk/usr/include/c++/v1/iterator:419:
[build] /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX12.1.sdk/usr/include/c++/v1/__functional_base:80:16: error: no template named 'unary_function'; did you mean 'binary_function'?
[build]         static unary_function<_Ap, _Rp>

最后,我搜索了整个项目,并确定这些必须是Boost使用unary_function,(据报道从C++ 17中删除)产生的。

代码语言:javascript
运行
复制
set(CMAKE_CXX_STANDARD 14)

在我的CMakeLists.txt里。

关于这个错误的网络搜索并没有显示出任何解决方案,但它确实出现了一些评论,询问苹果是否以某种方式破坏了前C++17的支持。我不知道如何实现对不同C++标准的支持。SDKs/MacOSX12.1.sdk/usr/include/c++/v1 (从错误输出中)提供了线索吗?

这是响亮的电话:

代码语言:javascript
运行
复制
/usr/bin/clang++ -D_HAS_AUTO_PTR_ETC=0 -I/Users/me/data/series2server/include -I/Users/me/data/series2server/restbed/include -I/Users/me/data/series2server -I/Users/me/data/series2server/restbed_server/api -I/Users/me/data/series2server/restbed_server/model -g -arch arm64 -arch x86_64 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX12.3.sdk -pthread -std=gnu++14 -MD -MT CMakeFiles/Series2Server.dir/main.cpp.o -MF CMakeFiles/Series2Server.dir/main.cpp.o.d -o CMakeFiles/Series2Server.dir/main.cpp.o -c /Users/me/data/series2server/main.cpp

使用unary_function的Boost 1.80.0文件是:

代码语言:javascript
运行
复制
functional.hpp
hash.hpp
logical.hpp
unique_ptr.hpp

以下是在操作系统11.6.8下Intel上的一系列错误:

代码语言:javascript
运行
复制
In file included from /Users/me/data/series2server/main.cpp:3: THIS LINE SAYS #include <string>
In file included from .../MacOSX12.1.sdk/usr/include/c++/v1/string:511:
In file included from .../MacOSX12.1.sdk/usr/include/c++/v1/string_view:179:
In file included from .../MacOSX12.1.sdk/usr/include/c++/v1/__string:57:
In file included from .../MacOSX12.1.sdk/usr/include/c++/v1/algorithm:652:
In file included from .../MacOSX12.1.sdk/usr/include/c++/v1/utility:206:
In file included from .../MacOSX12.1.sdk/usr/include/c++/v1/__debug:14:
In file included from .../MacOSX12.1.sdk/usr/include/c++/v1/iosfwd:95:
In file included from .../MacOSX12.1.sdk/usr/include/c++/v1/wchar.h:119:
In file included from .../MacOSX12.1.sdk/usr/include/wchar.h:91:
In file included from /Users/me/data/series2server/restbed_server/model/time.h:24: THIS LINE SAYS #include <memory>
In file included from .../MacOSX12.1.sdk/usr/include/c++/v1/memory:676:
In file included from .../MacOSX12.1.sdk/usr/include/c++/v1/iterator:419:
.../MacOSX12.1.sdk/usr/include/c++/v1/__functional_base:80:16: error: no template named 'unary_function'; did you mean 'binary_function'?
        static unary_function<_Ap, _Rp>

以下是OS12.5.1下M1上的错误堆栈:

代码语言:javascript
运行
复制
In file included from /Users/me/data/series2server/main.cpp:3: THIS LINE SAYS #include<string>
In file included from .../MacOSX12.3.sdk/usr/include/c++/v1/string:519:
In file included from .../MacOSX12.3.sdk/usr/include/c++/v1/__debug:14:
In file included from .../MacOSX12.3.sdk/usr/include/c++/v1/iosfwd:98:
In file included from .../MacOSX12.3.sdk/usr/include/c++/v1/__mbstate_t.h:29:
In file included from .../MacOSX12.3.sdk/usr/include/c++/v1/wchar.h:123:
In file included from .../MacOSX12.3.sdk/usr/include/wchar.h:91:
In file included from /Users/me/data/series2server/restbed_server/model/time.h:24: THIS LINE SAYS #include <memory>
In file included from .../MacOSX12.3.sdk/usr/include/c++/v1/memory:674:
In file included from .../MacOSX12.3.sdk/usr/include/c++/v1/__memory/allocator.h:18:
.../MacOSX12.3.sdk/usr/include/c++/v1/stdexcept:83:32: error: unknown type name 'string'
    explicit logic_error(const string&);

最后注意:这是因为代码生成器创建了一个名为Time.h的文件,这显然导致了这些错误;我的猜测是,在其他地方出现了与同名文件的冲突。

EN

回答 2

Stack Overflow用户

发布于 2022-08-31 01:42:28

无论是Boost我们的Apple似乎都配置错了。Boost肯定可以用C++17编译。如果配置正确,Boost将被定义为宏_HAS_AUTO_PTR_ETC=0并成功地使用C++17编译。参见functional.hpp

代码语言:javascript
运行
复制
#if defined(_HAS_AUTO_PTR_ETC) && !_HAS_AUTO_PTR_ETC
        // std::unary_function and std::binary_function were both removed
        // in C++17.

        template <typename Arg1, typename Result>
        struct unary_function
        {
            typedef Arg1 argument_type;
            typedef Result result_type;
        };

        template <typename Arg1, typename Arg2, typename Result>
        struct binary_function
        {
            typedef Arg1 first_argument_type;
            typedef Arg2 second_argument_type;
            typedef Result result_type;
        };
#else
        // Use the standard objects when we have them.

        using std::unary_function;
        using std::binary_function;
#endif

可以添加到CMakeLists.txt中。

代码语言:javascript
运行
复制
target_compile_definitions(${TARGET} _HAS_AUTO_PTR_ETC=0)
票数 1
EN

Stack Overflow用户

发布于 2022-08-31 08:07:35

这个项目中的很多代码都是从OpenAPI文档中生成的。其中一个生成的类被称为Time。尽管它被表达在几个嵌套的命名空间中,但在某些时候,它似乎引起了与其他一些时间类或文件的混淆,并导致了这些模糊的错误。

重新命名OpenAPI文档中的时间架构,然后重新生成类似乎解决了这些问题。

谢谢你的反馈。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/73549468

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档