I'm trying to build Box2D on macOS 14.8.7 (Apple M1 Pro). The build fails in the implot dependency because it uses features from a newer C++ standard version than what Clang uses by default:
$ git clone git@github.com:erincatto/box2d.git
Cloning into 'box2d'...
remote: Enumerating objects: 13890, done.
remote: Counting objects: 100% (1161/1161), done.
remote: Compressing objects: 100% (506/506), done.
remote: Total 13890 (delta 950), reused 662 (delta 651), pack-reused 12729 (from 3)
Receiving objects: 100% (13890/13890), 17.56 MiB | 13.89 MiB/s, done.
Resolving deltas: 100% (8853/8853), done.
$ cd box2d/
$ cmake --preset macos
-- The C compiler identification is AppleClang 16.0.0.16000026
-- The CXX compiler identification is AppleClang 16.0.0.16000026
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- CMake C compiler: AppleClang
-- CMake C++ compiler: AppleClang
-- CMake system name: Darwin
-- CMake host system processor: arm64
-- Box2D on Apple
-- Adding Box2D unit tests
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD - Success
-- Found Threads: TRUE
-- Including Cocoa support
nfd Platform: PLATFORM_MACOS
nfd Compiler: COMPILER_GNU
-- Performing Test NFD_USE_ALLOWEDCONTENTTYPES
-- Performing Test NFD_USE_ALLOWEDCONTENTTYPES - Success
-- Configuring done (33.7s)
-- Generating done (0.0s)
-- Build files have been written to: [...]/box2d/build
$ cmake --build --preset macos-release
The full output is in cmake-build.txt. The relevant errors start with this, I think:
CompileC /Users/michi/Downloads/box2d/build/build/implot.build/Release/Objects-normal/arm64/implot_items.o /Users/michi/Downloads/box2d/build/_deps/implot-src/implot_items.cpp normal arm64 c++ com.apple.compilers.llvm.clang.1_0.compiler (in target 'implot' from project 'box2d')
cd /Users/michi/Downloads/box2d
Using response file: /Users/michi/Downloads/box2d/build/build/implot.build/Release/Objects-normal/arm64/82b82416624d2658e5098eb0a28c15c5-common-args.resp
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang -x c++ -ivfsstatcache /var/folders/fq/2y7p86gs1qb98jp_cq5n90f80000gp/C/com.apple.DeveloperTools/16.2-16C5032a/Xcode/SDKStatCaches.noindex/macosx15.2-24C94-1dd28740b163f220e3e9b9fd2a542f53.sdkstatcache -fmessage-length\=80 -fdiagnostics-show-note-include-stack -fmacro-backtrace-limit\=0 -fcolor-diagnostics -Wno-trigraphs -Wno-missing-field-initializers -Wno-missing-prototypes -Wno-return-type -Wno-non-virtual-dtor -Wno-overloaded-virtual -Wno-exit-time-destructors -Wno-missing-braces -Wparentheses -Wswitch -Wno-unused-function -Wno-unused-label -Wno-unused-parameter -Wno-unused-variable -Wunused-value -Wno-empty-body -Wno-uninitialized -Wno-unknown-pragmas -Wno-shadow -Wno-four-char-constants -Wno-conversion -Wno-constant-conversion -Wno-int-conversion -Wno-bool-conversion -Wno-enum-conversion -Wno-float-conversion -Wno-non-literal-null-conversion -Wno-objc-literal-conversion -Wshorten-64-to-32 -Wno-newline-eof -Wno-c++11-extensions -Wno-implicit-fallthrough -fstrict-aliasing -Wdeprecated-declarations -Winvalid-offsetof -Wno-sign-conversion -Wno-infinite-recursion -Wno-move -Wno-comma -Wno-block-capture-autoreleasing -Wno-strict-prototypes -Wno-range-loop-analysis -Wno-semicolon-before-method-body @/Users/michi/Downloads/box2d/build/build/implot.build/Release/Objects-normal/arm64/82b82416624d2658e5098eb0a28c15c5-common-args.resp -MMD -MT dependencies -MF /Users/michi/Downloads/box2d/build/build/implot.build/Release/Objects-normal/arm64/implot_items.d --serialize-diagnostics /Users/michi/Downloads/box2d/build/build/implot.build/Release/Objects-normal/arm64/implot_items.dia -c /Users/michi/Downloads/box2d/build/_deps/implot-src/implot_items.cpp -o /Users/michi/Downloads/box2d/build/build/implot.build/Release/Objects-normal/arm64/implot_items.o
In file included from /Users/michi/Downloads/box2d/build/_deps/implot-src/implot_items.cpp:29:
In file included from /Users/michi/Downloads/box2d/build/_deps/implot-src/implot.h:49:
/Users/michi/Downloads/box2d/build/_deps/imgui-src/imgui.h:298:5: error:
unknown type name 'constexpr'
298 | constexpr ImVec2() : x(0.0f), y(0.0f) { }
| ^
/Users/michi/Downloads/box2d/build/_deps/imgui-src/imgui.h:298:15: error:
constructor cannot have a return type
298 | constexpr ImVec2() : x(0.0f), y(0.0f) { }
| ^~~~~~
Adding this to the top-level CMakeLists.txt fixes the problem and results in a successful build. I don't know enough about CMake to know what a proper way to fix this would be:
diff --git a/CMakeLists.txt b/CMakeLists.txt
index d5ed6a1..ec8f7e3 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -8,6 +8,8 @@ project(box2d
LANGUAGES C CXX
)
+set(CMAKE_CXX_STANDARD 17)
+
# stuff to help debug cmake
# message(STATUS "cmake tool chain: ${CMAKE_TOOLCHAIN_FILE}")
# message(STATUS "cmake source dir: ${CMAKE_SOURCE_DIR}")
I'm trying to build Box2D on macOS 14.8.7 (Apple M1 Pro). The build fails in the implot dependency because it uses features from a newer C++ standard version than what Clang uses by default:
The full output is in cmake-build.txt. The relevant errors start with this, I think:
Adding this to the top-level
CMakeLists.txtfixes the problem and results in a successful build. I don't know enough about CMake to know what a proper way to fix this would be: