How to: Bullet Physics in Visual Studio 2012

Standard

I’m going to use Bullet Physics in a university course this semester, as usual, the online documentation to create projects from scratch always lacks something / are outdated / all sorts of useless time consuming crap.

Creating a project from scratch with Bullet is actually pretty simple, this are the steps:

In this example I’m supposing you downloaded the file “bullet-2.81-rev2613.zip” and extracted it to “c:\bullet-2.81-rev2613”

  • Bullet comes already with all the compiled to your environment, but you can compile them for yourself using CMake ( Bullet wiki has a fairly good tutorial on this ) or Premake4. We are going to use the ones that already come with Bullet for simplicity.
  • Create a new C++ Win32 Console Project (I recommend that you use the Precompiled Headers, if you don’t know what they are, google it 😉 )
  • Now Add all the Bullet projects you need. For this example, in VS go to File>Add> Existing Project and, separately, add:
  1. c:\bullet-2.81-rev2613\build\vs2010\BulletCollision.vcxproj
  2. c:\bullet-2.81-rev2613\build\vs2010\BulletDynamics.vcxproj
  3. c:\bullet-2.81-rev2613\build\vs2010\LinearMath.vcxproj
  • In Solution Explorer, go to your project Properties (select it and ALT+ENTER)
  • Go to Common Properties> Framework and References and click on “Add New References…”. Choose all the projects you’ve previosly added
  • Click on Configuration Properties
  • At the top, change Configuration to All Configurations
  • Go to Configuration Properties> C/C++> General
  • In Additional Include Directories, add c:\Bullet-2.81-rev2613\src\

That’s it.

To test it, use this code in your project .cpp:

#include "stdafx.h"
#include "btBulletDynamicsCommon.h"
int _tmain(int argc, _TCHAR* argv[]){
btBoxShape * box = new btBoxShape(btVector3(1,1,1));
delete box;
return 0;
}

Did it run or did you got this error?

If so, the projects you’ve added have weird references. Do this:

  • In each added project, go to project Properties Page (ALT+ENTER)
  • In Common Properties> Framework and References, remove references to ZERO_CHECK

Run it again. Worked?

Compiled

Advertisements

23 thoughts on “How to: Bullet Physics in Visual Studio 2012

  1. Kévin

    I get errors when I try this tutorial on my Visual Studio 2012… It says I must update the code, but when I do it I get even more errors.

  2. Tareq

    I’m getting a LNK2038 error: LNK2038: mismatch detected for ‘RuntimeLibrary’: value ‘MT_StaticRelease’ doesn’t match value ‘MD_DynamicRelease’ in BulletTest.obj T:\My Documents\Visual Studio 2012\Projects\BulletTest\BulletTest\BulletCollision_vs2010.lib(btCollisionShape.obj)

    Not sure if its the error you mentioned since the picture isn’t showing up :S

    • Tareq

      Ok, image finally shown up. Problem is I can’t do the ZERO_CHECK on each of the projects, nothing is being shown in the Framework and References

      • Yes you’re correct, it is something different.

        Try this:
        1. Go to your project properties
        2. Go to Configuration Properties> C/C++ > Code Generation
        3. Change Runtime Library to Multi-threaded Debug DLL (for your Debug configuration, Multi-threaded DLL for your Release config)

        If it works, great, but don’t forget to research the differences between those configurations just for the sake of knowing what you’re doing.

        Give me feedback if this solved your problem.

  3. “Error 1 error MSB8020: The build tools for Visual Studio 2010 (Platform Toolset = ‘v100’) cannot be found. To build using the v100 build tools, please install Visual Studio 2010 build tools. Alternatively, you may upgrade to the current Visual Studio tools by selecting the Project menu or right-click the solution, and then selecting “Upgrade Solution…”. C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V120\Microsoft.Cpp.Platform.targets 64 5 BulletCollision”

    I’m currently using microsoft visual studio express 2013 so i don’t understand why its asking me to update

    • Thanks for posting this, I need to add some info to the original post.

      As Bullet doesn’t have compiled bin’s for anything up VS2010, you’ll need to have it installed so VS2013 can use VS2010 compiler, because as you can see for the error, VS2013 can’t find the compiler that is set to use in BulletCollision project, as you can check in the used path \build\vs2010\. Check if installing VS2010 Express Desktop solves the problem.

      To be fair, the best alternative would be to have Bullet compiled to VS2012 / VS2013, if you have the knowledge to extrapolate a new premake4 build config for VS2012 and VS2013 compilers, give those guys a hand! (or at least search if someone has already done it )

  4. Laxmi

    nothing is shown in output screen eventhough there is 0 errors. the output screen just holds saying”press anykey to continue”

    • It means that everything is ok and well configured.

      If you read the code, you’re just creating a box shape and deleting it, if you had some configuration problem (which is the focus of this post), you would get compilation or run-time errors.

      If you didn’t understand this or if it wasn’t that clear tell me and I’ll update the article accordingly.

  5. Dale Griffiths

    You are a genius and I love you. Ok maybe not the love you bit but I was so disenchanted with trying to get bullet physics to work with my partly made dx11 work that I was just about to jack all in and move across to opengl (suggestion from a friend) I even bought the superbible 6 on kindle. But now at least bullet has slotted into my program and the whizzing about balls are still wizzing about in the sky I am a happy chicken and now ready to start to do a bit of collision detection.
    thanks again.
    D.G.

    • Hi D.G.

      Oh man, your comment just made my day, you’re kindly welcome and I’m glad it solved your problem!

      Regarding your friends suggestion, it wouldn’t change anything because OpenGL only deals with rendering, this same setup would be required (I for one developed a physics sample using bullet and OpenGL for rendering btw). But yeah I know the desperate feel, this was a pain in the a** to come up with 🙂

  6. ddrozo@hotmail.com

    Hi. my name is David, i’m trying to work with Bullet on Visual Studio 2012 and after solve the problem with the ZERO_CHECK (Thank for you help), it show another problem. After Build the code that you present in the top, VS2012 show 4 errors:
    1) error LNK1104: cannot open file ‘..\..\lib\Debug\Bullet3Geometry_Debug.lib’
    2) Error 2 error LNK1104: cannot open file ‘..\..\lib\Debug\Bullet3Collision_Debug.lib’
    3) error LNK1104: cannot open file ‘..\..\lib\Debug\Bullet3Common_Debug.lib’
    If you know how to solve that problem? i like to know.

    Thanks for you time and help

  7. I have tried several different ways of setting up Bullet in Visual Studio 2013. I always get the same errors every time. I am trying to set up Bullet 3 (The same errors happen when trying to build previous versions)

    1>PhysicsHandling.obj : error LNK2019: unresolved external symbol “public: __thiscall btCollisionDispatcher::btCollisionDispatcher(class btCollisionConfiguration *)” (??0btCollisionDispatcher@@QAE@PAVbtCollisionConfiguration@@@Z) referenced in function “public: void __thiscall PhysicsHandling::Init(void)” (?Init@PhysicsHandling@@QAEXXZ)

    1>PhysicsHandling.obj : error LNK2019: unresolved external symbol “public: __thiscall btDefaultCollisionConfiguration::btDefaultCollisionConfiguration(struct btDefaultCollisionConstructionInfo const &)” (??0btDefaultCollisionConfiguration@@QAE@ABUbtDefaultCollisionConstructionInfo@@@Z) referenced in function “public: void __thiscall PhysicsHandling::Init(void)” (?Init@PhysicsHandling@@QAEXXZ)

    1>PhysicsHandling.obj : error LNK2019: unresolved external symbol “public: __thiscall btDbvtBroadphase::btDbvtBroadphase(class btOverlappingPairCache *)” (??0btDbvtBroadphase@@QAE@PAVbtOverlappingPairCache@@@Z) referenced in function “public: void __thiscall PhysicsHandling::Init(void)” (?Init@PhysicsHandling@@QAEXXZ)

    It shouldn’t be a linker error as I’ve tried both debug and release. I can build Bullet fine but when I try to use it in my own program it gives these errors.

    • It most definitely looks like a linker error due to missing configuration in your project. Check a tutorial on that just so you go through all of it again, you might be missing something.

  8. Benjamin

    I have tried this and about 5 other tutorials, each one has failed to work. The errors I keep getting for this one (different for every tutorial) is: error LNK2038 mismtach detected for ‘RuntimeLibrary’: value ‘MTd_StaticDebug’ doesn’t match value ‘MDd_DynamicDebug’ in PhysicsTest.obj

    Would anyone be able to help me with this?

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s