首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >无法在macos上成功编译c++

无法在macos上成功编译c++
EN

Stack Overflow用户
提问于 2022-03-04 04:12:13
回答 1查看 379关注 0票数 -2

我的MacOS版本是12.2.1,sdk是12.1,我以前可以成功地构建它,但是现在它在我完成xcode升级之后就失败了。

这是一些错误信息。

代码语言:javascript
运行
复制
In file included from /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX12.1.sdk/usr/include/c++/v1/vector:276:
In file included from /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX12.1.sdk/usr/include/c++/v1/__bit_reference:15:
In file included from /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX12.1.sdk/usr/include/c++/v1/algorithm:653:
In file included from /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX12.1.sdk/usr/include/c++/v1/memory:676:
In file included from /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX12.1.sdk/usr/include/c++/v1/iterator:419:
/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'?
        static unary_function<_Ap, _Rp>
               ^
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX12.1.sdk/usr/include/c++/v1/__functional_base:27:29: note: 'binary_function' declared here
struct _LIBCPP_TEMPLATE_VIS binary_function
                            ^
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX12.1.sdk/usr/include/c++/v1/__functional_base:80:16: error: too few template arguments for class template 'binary_function'
        static unary_function<_Ap, _Rp>
               ^
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX12.1.sdk/usr/include/c++/v1/__functional_base:27:29: note: template is declared here
struct _LIBCPP_TEMPLATE_VIS binary_function
                            ^
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX12.1.sdk/usr/include/c++/v1/__functional_base:81:31: error: no template named 'unary_function'; did you mean 'binary_function'?
        __test(const volatile unary_function<_Ap, _Rp>*);
                              ^
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX12.1.sdk/usr/include/c++/v1/__functional_base:27:29: note: 'binary_function' declared here
struct _LIBCPP_TEMPLATE_VIS binary_function
                            ^
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX12.1.sdk/usr/include/c++/v1/__functional_base:81:31: error: too few template arguments for class template 'binary_function'
        __test(const volatile unary_function<_Ap, _Rp>*);
                              ^
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX12.1.sdk/usr/include/c++/v1/__functional_base:27:29: note: template is declared here
struct _LIBCPP_TEMPLATE_VIS binary_function
                            ^
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX12.1.sdk/usr/include/c++/v1/__functional_base:168:14: error: no template named 'unary_function'; did you mean 'binary_function'?
    : public unary_function<_A1, _Rp>
             ^
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX12.1.sdk/usr/include/c++/v1/__functional_base:27:29: note: 'binary_function' declared here
struct _LIBCPP_TEMPLATE_VIS binary_function

我的心愿是

代码语言:javascript
运行
复制
cmake_minimum_required(VERSION 3.0)
project(mytest VERSION 1.0.0)
cmake_policy(SET CMP0074 NEW)
set(CMAKE_CXX_STANDARD 11)
add_compile_options(-stdlib=libc++)
EN

回答 1

Stack Overflow用户

发布于 2022-03-04 06:58:44

默认情况下,与实际xcode一起提供的clang支持C++17。

std::unary_function在C++17中被删除。应该使用std::function

set(CMAKE_CXX_STANDARD 11)太迟了。它应该放在project(mytest VERSION 1.0.0)之前,否则默认的标准C++17设置为完美。

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

https://stackoverflow.com/questions/71346528

复制
相关文章

相似问题

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