如何在Linux中编译Box2D? [英] How to compile Box2D in Linux?

查看:196
本文介绍了如何在Linux中编译Box2D?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

编译Box2d Tesbed应该很简单:

Compiling the Box2d Tesbed is supposed to be simple:

来自 iforce2d


从此处下载Box2D源代码存档。如果您想完全使用终端,也可以这样做(如果wget不可用,请使用yum进行安装):

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. [...]

解压缩Box2D_v2.1.2.zip
cd Box2D_v2.1.2 / Box2D / Build
cmake ..
make

(这些说明已经很老了,我确实知道了我的 git clone https://github.com/erincatto/Box2D.git

( These instructions are pretty old, I did get my source with git clone https://github.com/erincatto/Box2D.git )

正在运行<$新鲜克隆目录中的 Box2D / Build 中的c $ c> cmake .. 导致多个错误:

Running cmake .. from Box2D/Build in the freshly cloned directory causes multiple errors :

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

在这些站点上可以找到多个类似的问题,但是没有一个答案。我知道我可以使用
sudo apt-get install libox2d 安装box2d,但我也想拥有测试平台。

Multiple similar questions can be found on these sites, but none has an answer. I know I can install box2d with sudo apt-get install libox2d but I'd like to have the testbed as well.

这怎么办?

推荐答案

如果您具有 Box2D repo已签出,您可以通过在存储库目录中运行以下git命令来还原原始CMake文件:

If you have the most recent commit from the Box2D repo checked out, you can restore the original CMake files by running this git command in the repository directory:

git checkout 05ee3c3c22af9ac1e5d88061d0b473f814c8210f^ \
 Box2D/Box2D/Box2DConfig.cmake.in \
 Box2D/Box2D/CMakeLists.txt \
 Box2D/Box2D/UseBox2D.cmake \
 Box2D/CMakeLists.txt \
 Box2D/HelloWorld/CMakeLists.txt \
 Box2D/Testbed/CMakeLists.txt \
 Box2D/glew/CMakeLists.txt \
 Box2D/glfw/CMakeLists.txt

由于Box2D自此提交以来已开始使用C ++ 11功能,因此您需要将此行添加到 Box2D / CMakeLists.txt 中:

Since Box2D has started using C++11 features since this commit, so you will need to add this line to Box2D/CMakeLists.txt:

set (CMAKE_CXX_STANDARD 11)

如果您只想构建核心库,那么就完成了;只需运行以下命令:

If you only want the core library built, you're done; just run the following commands:

mkdir build
cd build
cmake -D BOX2D_BUILD_EXAMPLES=OFF ../Box2D



测试平台



在测试平台上,事情变得更加复杂。 Box2D的GLFW副本的CMakeLists似乎已完全损坏。打开 Box2D / CMakeLists.txt ,找到以下两行:

add_subdirectory(glew)
add_subdirectory(glfw)

用以下内容替换它们。这将导致该版本使用您库的系统版本,因此您需要安装它们:

Replace them with the following. This will cause the build to use your system versions of the libraries, so you will need to have them installed:

find_package(GLEW REQUIRED)
if (GLEW_FOUND)
  include_directories(${GLEW_INCLUDE_DIRS})
  link_libraries(${GLEW_LIBRARIES})
endif()

find_package(PkgConfig REQUIRED)
pkg_search_module(GLFW REQUIRED glfw3)
include_directories(${GLFW_INCLUDE_DIRS})

打开 Box2D / Testbed / CMakeLists.txt 。在文件顶部的 set(Testbed_Framework_SRCS )下,删除引用imgui和RenderGL3的4行。在该部分中添加以下行:

Open Box2D/Testbed/CMakeLists.txt. At the top of the file, under set(Testbed_Framework_SRCS, remove the 4 lines referring to imgui and RenderGL3. Add the following lines in that section:

../imgui/imgui.h
../imgui/imgui.cpp
../imgui/imgui_draw.cpp
../imgui/imgui_impl_glfw_gl3.cpp

滚动到底部并替换 glew glfw 行,其中:

Scroll to the bottom and replace the glew and glfw lines with:

${GLEW_LIBRARIES}
${GLFW_STATIC_LIBRARIES}

最后替换

文件(复制../Build/Data DESTINATION ..)

with

file(COPY ./Data DESTINATION。)

此时,完整的库和测试平台应该是可构建的:

At this point, the full library and testbed should be buildable:

mkdir build
cd build
cmake ../Box2D

这篇关于如何在Linux中编译Box2D?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆