0_1564880258942_box2d_logo.png


下载文件并进入目录

git clone -b v2.3.1 https://github.com/erincatto/Box2D.git
cd Box2D

整理下文件:

rm -rf ./Contributions
mv ./Box2D ./tmp
mv ./tmp/Box2D ./Box2D
rm -rf ./tmp
mkdir Lib
mkdir Include

添加CMakeLists.txt,内容如下:

cmake_minimum_required(VERSION 2.6)

project(Box2D)

# 若果要改成动态编译,将下面OFF 和 ON的位置对调
set(BOX2D_BUILD_SHARED OFF)
set(BOX2D_BUILD_STATIC ON)


set(BOX2D_VERSION 2.3.0)
set(LIB_INSTALL_DIR lib${LIB_SUFFIX})

add_subdirectory(Box2D)

编译安装

cmake .
make
mv ./Box2D/libBox2D.a ./Lib/libBox2D.a
mv ./Box2D/Box2D.h ./Include/Box2D.h
mv ./Box2D/Collision ./Include/Collision
mv ./Box2D/Common ./Include/Common
mv ./Box2D/Dynamics ./Include/Dynamics
mv ./Box2D/Rope ./Include/Rope
rm -rf Box2D
rm -rf ./cmake*
rm -rf ./CMake*
rm -rf Makefile

头文件在Include目录中,静态库在Lib目录中。


如果你懒得配置的话,这里有我配置好的,直接运行脚本就可以自己编译了:
https://github.com/guaik/Box2DInstaller.git