Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

hey the title pretty much says it all. i have been trying different methods from internet sources, but whenever i try something goes wrong..this is where i got Box2D

in cMake, i get a bunch of errors when building it(i was going through the steps in the readme.txt, but onfortunately, theyre for Visual C++...)

so im wondering hot to set this up as i guess a library (.lib or .a) and use it in my project(my friend passed me his library and when i loaded it in and tried #includeing the box2D headers, they didnt read at all(i got a list of undefined errors) also his box2d was i believe made for linux/unix so i think thats the reason...)

if anyone can help provide some steps that would be nice.

thanks for reading.

like image 472
Molmasepic Avatar asked Mar 30 '11 19:03

Molmasepic


1 Answers

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.

like image 95
Cory G. Avatar answered Sep 17 '22 22:09

Cory G.