Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
733 views
in Technique[技术] by (71.8m points)

c++ - How to compile Box2D in Linux?

Compiling the Box2d Tesbed is supposed to be simple:

from 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

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

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

Of course, make fails:

[ 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

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.

How can this be done ?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Short answer...

yes this can be built, rollback your git clone of Box2D until the build doesn't fail.

Long answer...

Seems you've encountered two separate problems:

  1. Not finding the imgui.h file.
  2. The introduction of nullptr to the Git source tree which requires C++11 or newer language acceptance from the compiler.

Regarding problem 1, there's been an issue filed about that back at the beginning of February 2017: issue 433. Regarding problem 2, there's also been an issue filed for this back in June 2016: issue 414.

While I did not see a resolution on GitHub for problem 1, problem 2 apparently is resolvable by applying pull request #412. You should also be able to resolve problem 2 by having your compiler accept C++11 (or newer).

As for resolving problem 1, you can roll back your git clone of Box2D until the Testbed can be built. If you rollback far enough, that should also resolve problem 2 (without needing to do anything else). Information on how to do the reversion can be found at the SO question of How to revert Git repository to a previous commit?.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...