How would I build Box2D to work in Code::Blocks/Mingw32(Windows)

放肆的年华 提交于 2019-11-30 20:56:36

Assumptions: You have installed cmake. You have installed Code::Blocks/MinGW to C:\codeblocks. You have downloaded Box2D and extracted it to C:\Box2D_v2.1.2.

If any of those are wrong, modify the paths to match what you have.

Start->Run->cmd.

Navigate to the Box2D "Build" folder:
cd C:\Box2D_v2.1.2\Box2D\Build

Create the makefiles:
cmake -G "MinGW Makefiles" ..

Do it:
mingw32-make

This will throw some warnings, but should work almost completely. Then, near the end, it will error trying to compile the Testbed. AFAIK, there is no way to compile the Testbed using MinGW (you have to use Visual Studio, I believe). Luckily, an .exe of it is available on the Box2D site.

In the Box2D\Build\Box2D folder, there should now be a file called libBox2D.a. Copy this file into C:\codeblocks\mingw\lib.

Copy the Box2D\Box2D folder (the one containing Box2D.h) into C:\codeblocks\mingw\include. [Thus, after this step, you should have a file C:\codeblocks\mingw\include\Box2D\Box2d.h, and NOT C:\codeblocks\mingw\include\Box2d.h]

And that's it. You should be able to compile and run the "Hello Box2D" example. Don't forget to link to the library.

[EDIT]

From the looks of your error, I'm going to guess that your MinGW Path environment variable is not setup correctly. Which is unusual, since when you install Code::Blocks/MinGW it usually sets it for you, I believe.

Anyway, (these steps may vary slightly depending on your version of Windows):

Right-click on "[My] Computer"-> Properties -> Advanced System Settings
Click "Environment Variables"
Depending on which Windows you have, you may see User Variables and System Variables, or it may be just one group (I can't remember the name). Anyway, create a new System Environment Variable called MINGDIR, with the value C:\codeblocks\mingw or wherever you installed it to. Then, find the variable called Path (or PATH) and append this to the end: C:\codeblocks\mingw\bin. Put a semicolon at the end of the previous entry, and do not use a space.
Also make sure that C:\CMake\bin is present in either the System Variable called Path, or the user variable called Path. If not, append it to the end.
I think that's it.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!