Mr. Dr. Doom
Mr. Dr. Doom

Reputation: 71

Build Box2D in x86 (Visual Studio)

Recently I implemented Box2D to our in-house game engine using C++11 and SDL2. A fresh install of Box2D will produce a x64 build. The engine had been built to run in x86 years prior so changing the architecture of the project just to match Box2D was out of the question.

I found a way to build in x86 that worked for me, so I wanted to post this as documentation to help out anyone struggling in the same way. If there is a better way to do it I welcome discussion on the topic.

So, how do I get Box2D to work with my project already built in x86?

Upvotes: 1

Views: 1397

Answers (1)

Mr. Dr. Doom
Mr. Dr. Doom

Reputation: 71

First, you'll need to install Box2D [Box2D - C++]. Open up the command prompt and clone the repo onto your computer, I chose to clone this at 'C:\temp\'

After you've finished pulling down the project, navigate inside the 'box2d' folder and run the build.bat script. This will install/compile everything you'll need to start working. The only downside is that it will build in x64 which might not work for everyone (if x64 works for you, you can stop reading. Congrats!)

Second, if it isn't already, install vcpkg. You can follow [this vcpkg guide] up to step 2 (Run the bootstrap script to build vcpkg). For convenience's sake install this at 'C:\temp\' too.

Once set up is done, use the command prompt to navigate into vcpkg directory. Then run the following:

 vcpkg install box2d

This will run another installation, once it's finished navigate to [path\to\vcpkg]\installed\x86-windows. Here you should find all your new lib and include files for Box2D.

Now you have the freedom to move these files wherever you need to for your projects. Edit your project's properties as needed and you'll be able to successfully run your code in x86!

Upvotes: 1

Related Questions