Box2D 官网

Box2D 安装
Download

Box2D GitHub 源码
https://github.com/erincatto/Box2D/

Building
https://github.com/erincatto/Box2D/blob/master/Building.md

premake5

Version 5.0 (alpha)
https://premake.github.io/download.html#v5

查看帮助
1 | premake5 --help |
2 | ... |
3 | ACTIONS |
4 | vs2019 Generate Visual Studio 2019 project files |
5 | xcode4 Generate Apple Xcode 4 project files |
6 | |
7 | For additional information, see https://premake.github.io |
Box2D master
1 | premake5 xcode4 |
下载:https://github.com/erincatto/Box2D/archive/master.zip

生成 Xcode 项目
Here are the steps for Xcode:
- Command line:
premake5 xcode4
- Open the resulting project file (should be Build/Box2D.xcworkspace)
- Set the Testbed as the current Scheme
- Edit the Testbed Scheme, in the Run Options, use a custom working directory
- Set the Testbed directory as the working directory
- Press
Command-R
to build and run the Testbed
1 | premake5 xcode4 |

Scheme
Run > Release

创建 Box2D Demo
macOS > Application > Command Line Tool

- Project Name:
Box2DDemo
- Language:
C++

头文件
把 Box2D-master
里面的 Box2D
文件夹复制到 Box2DDemo/Box2D/include
下

库文件
把 Box2D-master/Build/bin/x86_64/Release/libBox2D.a
复制到 Box2DDemo/Box2D/lib

添加库文件
- Build Phases
- Link Binary With Libraries
+
- Link Binary With Libraries

- Add Files
libBox2D.a

会自动设置 Build Settings > Library Search Path
配置头文件搜索路径
Header Search Path: $(PROJECT_DIR)/Box2D/include

Xcode 自动补全

测试一下
用 Box2D-master
里面的 Hello World
代码测试一下,可以正常执行

小结
源码:
https://github.com/GameDevLog/Box2DDemo
参考: