c++ - 如何在 Linux 中编译 Box2D?

标签 c++ compiler-errors cmake box2d gnu-make

编译 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 克隆,直到构建没有失败。

长答案...

您似乎遇到了两个不同的问题:

  1. 找不到 imgui.h 文件。
  2. 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/

相关文章:

CMake SET 命令未按预期工作(CMake 未设置预定义缓存变量的值)

c++ - 输出字符串用 C++ 在 Linux 中覆盖终端上的最后一个字符串

c++ - (CMake 构建) fatal error LNK1181 : cannot open input file 'glew.lib'

c++ - 将对象从 QML 传递到 C++

compiler-errors - 部署IBM Mobile v8.0.0 MobileFirst HTTP Adater错误- “Adapter deployment failed: A database error was detected.”

cmake - 如何制作CMake包?

c++ - 在 C++14 中使用 decltype(auto) 声明静态数据成员

java - 添加到通用列表<?> 产生编译错误

java - 安卓开发 : Error in AVD Emulator

c++ - CMake add_subdirectory 不调用子 CMakeLists.txt