Linking with VS 2010 express

Hello there. I've been trying to to implement Box2D with my C++/SFML project but I'm not sure how to do this. It's always such a hassle for me to link libraries because I don't quite understand it. I downloaded Box2D and unzipped it to my desktop. I read the building text file which says "The Build folder contains custom made project files for Visual Studio 2010 and XCode4.". Now I'm assuming I don't have to use CMake at all and everything that I need is here? I tried the HelloWorld project and it worked correctly and I checked out the project settings. It only links to the Box2D.lib if I'm correct. I tried to copy this so all I really did was put that Box2D.lib file in my project's directory where all my cpp files are. I'm only interested in the release version.


If someone could help me step by step then that would be great.

EDIT: I also copied the source(from Box2D_v2.2.1>Box2D...I hope that is right) into my project.

EDIT2: I removed that for now because I can't compile .h files so I did something wrong
The build files are provided mainly as a convenience for running the testbed. I recommend that you manually create a project file and add the main Box2D source to that project. Then setup the project dependencies so your application depends on the Box2D project.
Thanks, I did that and everything was set up properly...well almost.

I can create gravity, but when I try to create a world I get a bunch of

Code: Select all

Error   18   error LNK2038: mismatch detected for '_ITERATOR_DEBUG_LEVEL': value '2' doesn't match value '0' in CollisionLayer.obj   C:\Users\Mathew\Documents\Visual Studio 2010\Projects\ColonyGame\ColonyGame\Box2D.lib(b2World.obj)


and

Code: Select all

Error   62   error LNK1319: 42 mismatches detected   C:\Users\Mathew\Documents\Visual Studio 2010\Projects\ColonyGame\Release\ColonyGame.exe


Now I've run into a problem like this when I was setting up SFML. Defining '_ITERATOR_DEBUG_LEVEL' as a constant 0 fixed it but broke something else. In the end I just put my project in to release and it works. But I'm still getting this error in release mode.

EDIT: Wait, I may have built the debug version by accident. I will check it now.
SOLVED!

I was right 🙂 I built the release binaries and used those and it works like a charm now. Thanks for the help, Erin.
Erin Catto wrote:The build files are provided mainly as a convenience for running the testbed. I recommend that you manually create a project file and add the main Box2D source to that project. Then setup the project dependencies so your application depends on the Box2D project.


I'm having trouble myself, this is exactly what I want/am trying to do, but it causes me to have to change "#include <Box2D/Box2D.h>" to "#include "Box2D/Box2D.h" ", everywhere. I don't want to change the box2d sources. isn't there a step by step guide out there for using this with Visual C++ 2010 Express? I don't want to reuse the hello world project either because I don't want my project to be called Hello World. I can't quite figure out how to include the .lib either.
Venevus wrote:
Erin Catto wrote:The build files are provided mainly as a convenience for running the testbed. I recommend that you manually create a project file and add the main Box2D source to that project. Then setup the project dependencies so your application depends on the Box2D project.


I'm having trouble myself, this is exactly what I want/am trying to do, but it causes me to have to change "#include <Box2D/Box2D.h>" to "#include "Box2D/Box2D.h" ", everywhere. I don't want to change the box2d sources. isn't there a step by step guide out there for using this with Visual C++ 2010 Express? I don't want to reuse the hello world project either because I don't want my project to be called Hello World. I can't quite figure out how to include the .lib either.


oh boy, this is one thing (i'm probably missing another step, i'll get to that in a moment); in your project in visual cpp, right click, click "References", under "Configuration Properties -> C/C++ -> General", in the "Additional Include Directories" field, make sure you have added your box2D folder (same as it appears in the given Hello World program).

Also, I add the project "Box2D" to my dependencies for my project, but I don't yet know if that's necessary or not.

Original thread: https://box2d.org/forum/viewtopic.php?t=8395