'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.
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_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++)
Solution 1:[1]
The clang supplied with the actual xcode supports C++17 by default.
std::unary_function is removed in C++17. std::function should be used instead.
You set(CMAKE_CXX_STANDARD 11) too late. It should be placed before project(mytest VERSION 1.0.0), otherwise the default standard C++17 is set to the perfect.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 |
