0

I have a pretty simple CMake-based project that builds one lib and a small executable that uses it. It builds fine on Linux with GCC, but fails on Mac OS with loads of errors of the following kind. The inciting line of code in main.cpp is the second one here:

#include <cstdlib>
#include <memory>

The first of many similar errors:

[build] In file included from /Users/me/data/series2server/main.cpp:2:
[build] In file included from /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX12.3.sdk/usr/include/c++/v1/memory:671:
    [build] /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX12.3.sdk/usr/include/c++/v1/__algorithm/search.h:34:19: error: no member named 'make_pair' in namespace 'std::__1'
    [build]     return _VSTD::make_pair(__first1, __first1); // Everything matches an empty sequence

This appears to be a mismatch between Clang and GCC uses of std. But I can't figure out why CMake is configuring things to call clang++ but putting "std=gnu++14" in the compiler invocation. I did a full-text search for "std=gnu" in the whole source tree and didn't find it. I do see this in various CMakeLists.txt files:

set( CMAKE_CXX_STANDARD 14 )

A compiler invocation is below. Where might I look for where this gnu option is specified? Thanks!

[build] cd /Users/me/data/series2server/build/restbed && /usr/bin/clang++ -DBUILD_SSL -I/Users/me/data/series2server/restbed/source -isystem /Users/me/data/series2server/restbed/dependency/asio/asio/include -isystem /Users/me/data/series2server/restbed/dependency/openssl/include -Wall -Wextra -Weffc++ -pedantic -Wno-unknown-pragmas -Wno-deprecated-declarations -Wno-non-virtual-dtor -DASIO_STANDALONE=YES -Wno-deprecated-declarations -g -arch arm64 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX12.3.sdk -std=gnu++14 -MD -MT restbed/CMakeFiles/restbed-static.dir/source/corvusoft/restbed/detail/service_impl.cpp.o -MF CMakeFiles/restbed-static.dir/source/corvusoft/restbed/detail/service_impl.cpp.o.d -o CMakeFiles/restbed-static.dir/source/corvusoft/restbed/detail/service_impl.cpp.o -c /Users/me/data/series2server/restbed/source/corvusoft/restbed/detail/service_impl.cpp
Oscar
  • 2,039
  • 2
  • 29
  • 39
  • 2
    This looks like a conflict between `libstdc++` (gcc's C++ standard library implementation) and `libc++` (Clang's C++ standard library implementation). Check your verbose build output for anything that might be trying to build with g++, or anyplace that's adding `libstdc++`'s include path. – Stephen Newell Aug 12 '22 at 00:07
  • Thanks for the reply. I knew that this result implied a GCC/CLang conflict, but couldn't see any Gnu reference. But after activating verbose mode in CMakeLists.txt, I'm guessing this is the offending nugget in the call to clang++: -std=gnu++14. Now the question is where this is coming from. – Oscar Aug 12 '22 at 14:37
  • You didn't post your cmake file. `I did a full-text search for "std=gnu"` That's not the only way to set std https://stackoverflow.com/questions/10851247/how-do-i-activate-c-11-in-cmake . – KamilCuk Aug 13 '22 at 05:49
  • @KamilCuk Thanks for the reply. I looked at that post and didn't see anything specific to explain it. I did add info above about finding set( CMAKE_CXX_STANDARD 14 ) in CMakeLists.txt. – Oscar Aug 13 '22 at 07:28
  • `I did add info above about finding set( CMAKE_CXX_STANDARD 14 ) in CMakeLists.txt.` ? So it explains it? Post it as an answer. Note that your question is __not__ how to fix your problem, or why there is incompatibility, or how to fix it, your question is specifically about `Why is CMake putting an erroneous "std=gnu++14" in Clang invocations?`. It is putting because there is set( CMAKE_CXX_STANDARD 14 ) in CMakeLists.txt – KamilCuk Aug 13 '22 at 07:35
  • 3
    `set( CMAKE_CXX_STANDARD 14 )` sets `gcc` or `clang` flag to `-std=gnu++14`, **unless** `CXX_EXTENSIONS` property (or `CMAKE_CXX_EXTENSIONS` variable) is set to `OFF`. In this case it uses `-std=c++14`. This has nothing to do with the error you are seeing though. Please post a [mcve]. – n. m. could be an AI Aug 13 '22 at 07:48
  • @n.1.8e9-where's-my-sharem. Thanks. If you post that as an answer, I'll mark it as such. I'm not able to whittle the project down enough to post it anywhere right now. – Oscar Aug 17 '22 at 22:07

1 Answers1

1

From n.m.'s comment 10 years ago, for clarity:

set( CMAKE_CXX_STANDARD 14 ) sets gcc or clang flag to -std=gnu++14, unless CXX_EXTENSIONS property (or CMAKE_CXX_EXTENSIONS variable) is set to OFF. 
Asher
  • 1,195
  • 1
  • 11
  • 19