简体   繁体   English

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

[英]can't compile c++ successfully on macos

my MacOS version is 12.2.1 and sdk version is 12.1 I can build it successfully before, but now it fail after I finish upgrading my xcode.我的MacOS版本是12.2.1,sdk版本是12.1,之前可以成功搭建,现在升级完xcode就失败了。

this is some error info.这是一些错误信息。

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


my cmake confige is that我的 cmake 配置是


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++)


The clang supplied with the actual xcode supports C++17 by default.与实际 xcode 一起提供的 clang 默认支持 C++17。

std::unary_function is removed in C++17. std::function should be used instead. std::unary_function在 C++17 中被移除。应该使用std::function代替。

You set(CMAKE_CXX_STANDARD 11) too late.set(CMAKE_CXX_STANDARD 11)太晚了。 It should be placed before project(mytest VERSION 1.0.0) , otherwise the default standard C++17 is set to the perfect.它应该放在project(mytest VERSION 1.0.0)之前,否则默认标准 C++17 设置为完美。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM