编译 Box2d Tesbed 应该很简单:
来自 iforce2d :
Download the Box2D source code archive from here. If you want to use the terminal all the way, you could also do this (if wget is not available, use yum to install it):
wget http://box2d.googlecode.com/files/Box2D_v2.1.2.zip
Use the following commands to unzip and build it. [...]
unzip Box2D_v2.1.2.zip cd Box2D_v2.1.2/Box2D/Build cmake .. make
(这些说明很旧,我确实通过 git clone https://github.com/erincatto/Box2D.git
获得了源代码)
从新克隆的目录中的 Box2D/Build
运行 cmake ..
会导致多个错误:
CMake Error at Testbed/CMakeLists.txt:84 (add_executable):
Cannot find source file:
Framework/imgui.h
Tried extensions .c .C .c++ .cc .cpp .cxx .m .M .mm .h .hh .h++ .hm .hpp
.hxx .in .txx
CMake Error: Cannot determine link language for target "glfw".
CMake Error: CMake can not determine linker language for target: glfw
当然,make
失败了:
[ 42%] Building CXX object Box2D/CMakeFiles/Box2D.dir/Dynamics/b2Body.cpp.o
/home/cabri/Documents/Box2D/Box2D/Box2D/Dynamics/b2Body.cpp: In member function ‘void b2Body::DestroyFixture(b2Fixture*)’:
/home/cabri/Documents/Box2D/Box2D/Box2D/Dynamics/b2Body.cpp:216:17: error: ‘nullptr’ was not declared in this scope
if (fixture == nullptr)
^
Box2D/CMakeFiles/Box2D.dir/build.make:566: recipe for target 'Box2D/CMakeFiles/Box2D.dir/Dynamics/b2Body.cpp.o' failed
make[2]: *** [Box2D/CMakeFiles/Box2D.dir/Dynamics/b2Body.cpp.o] Error 1
CMakeFiles/Makefile2:85: recipe for target 'Box2D/CMakeFiles/Box2D.dir/all' failed
make[1]: *** [Box2D/CMakeFiles/Box2D.dir/all] Error 2
Makefile:127: recipe for target 'all' failed
make: *** [all] Error 2
在这些网站上可以找到多个类似的问题,但没有一个有答案。我知道我可以安装 box2d
sudo apt-get install libox2d
但我也想拥有测试平台。
如何做到这一点?
最佳答案
简答...
是的,这可以构建,回滚 Box2D 的 git 克隆,直到构建没有失败。
长答案...
您似乎遇到了两个不同的问题:
- 找不到
imgui.h
文件。 - 将
nullptr
引入 Git 源代码树,这需要编译器接受 C++11 或更新的语言。
关于问题 1,早在 2017 年 2 月初就有一个问题提交:issue 433 .关于问题 2,早在 2016 年 6 月也有人为此提出问题:issue 414 .
虽然我没有在 GitHub 上看到问题 1 的解决方案,但问题 2 显然可以通过应用 pull request #412 来解决。 .您还应该能够通过让编译器接受 C++11(或更新版本)来解决问题 2。
至于解决问题 1,您可以回滚 Box2D 的 git 克隆,直到可以构建 Testbed。如果回滚足够远,那也应该可以解决问题 2(无需执行任何其他操作)。有关如何进行还原的信息可以在 How to revert Git repository to a previous commit? 的 SO 问题中找到。 .
关于c++ - 如何在 Linux 中编译 Box2D?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42351640/