Guide to compiling OgreNewt with Ogre 1.7.2 & Newton 2.33

nww02

02-10-2011 23:08:10

For the last few days, I've been wrestling with getting the right sets of incantations to make Ogre, Newton and OgreNewt all work. For someone who's not primarily a C++ developer, like me, this can be quite daunting. The error messages, while moderately helpful don't include a "Now, do X", to help you fix it.

Anyway, here is the set of steps I took using the absolutely Vanilla downloads of Ogre, Newton and OgreNewt, to get a working trio of libraries. Your Mileage may vary. It's entirely possible I've missed a step, so if anyone finds a problem, post the fix.

Get The Sources

  1. Use Visual Studio 2008. I kept running into problems with VS2010, and as soon as I ditched it for 2008, everything started clicking into place.
    [/*:m]
  2. Download Newton Game Dynamics, and unpack into a folder, for example:
    D:\DEVELOPMENT\newton-dynamics-2.33
    [/*:m]
  3. Download OGRE: I suggest the VC2008 version. Unpack into a folder, for example:
    D:\DEVELOPMENT\OGRE
    This will generate a subfolder under this folder with the name/compiler/release of the sdk. Right now, that is OgreSDK_vc9_v1-7-2

    [/*:m]
  4. Download OgreNewt, and unpack into a folder, for example:
    D:\DEVELOPMENT\OGRENewt
    Sadly, although you can download it one file at a time using the above link, to get it all at once you'll need an SVN client. TortoiseSVN is my favourite.
    1. Download and install TortoiseSVN[/*:m]
    2. Create a subfolder of your dev folder called OgreNewt[/*:m]
    3. Right-click the folder and choose 'Check Out'[/*:m]
    4. Enter the URL for the Ogre-Addons Repo http://svn.ogre3d.org/svnroot/ogreaddons/branches/ogrenewt/newton20[/*:m]
    5. Click OK, and sit back as OgreNewt2.0 is brought to you.[/*:m][/list:u][/*:m][/list:u]



      Set Up some Env. Variables

      Now, add some 'HOME' variables. You don't have to do this, but it makes things easier:
      1. Right-click on My Computer, and select Properties. [/*:m]
      2. Under the advanced tab, select "Environment Variables"[/*:m]
      3. In the window which pops up, click "New", then add the following Variables:

        BOOST_HOME D:\DEVELOPMENT\ogre\OgreSDK_vc9_v1-7-2\boost_1_44
        NEWTON_HOME D:\DEVELOPMENT\newton-dynamics-2.33
        OGRE_HOME D:\DEVELOPMENT\OGRE\OgreSDK_vc9_v1-7-2
        OGRENEWT_HOME D:\DEVELOPMENT\OgreNewt[/*:m][/list:u]

        The reason why 'Ogre' is an extra level deep is that because you may want to have several ogre versions eventually, and when you unzip the distro, it adds the SDK foldername.


        Build Newton

        Newton comes with a precompiled library, but it's missing dmath, which you'll need for OgreNewt. Go into the Newton folders and find the packages\projects\visualstudio_2008 folder

        1. Double-click on build.sln
          [/*:m]
        2. Build the newton packages using all four configurations, Debug, DebugDLL, Release, ReleaseDLL
          [/*:m]
        3. Go to the packages\win32\debug folder and copy the dmath_d.lib, dScene_d.lib, tinyxml_d.lib and dContainers_d.lib into the packages\win32\debugDll folder. Don't copy the newton_d.lib and dJointLibrary_d.lib over the ones already created.
          [/*:m]
        4. Go to the packages\win32\release folder and copy the dmath.lib, dscene.lib, tinyxml.lib and dContainers.lib into the packages\win32\releaseDll folder. Don't copy the newton.lib and dJointLibrary.lib over the ones already created.[/*:m][/list:u]


          OK, now you've got Newton all compiled and the dmath libraries all compiled up and in one place. Excellent. Now, it's time to compile OgreNewt.


          Build OgreNewt

          Go into the OgreNewt folder, and open the OgreNewt_VS9.sln file. bring up the OgreNewt project's property page by right-clicking on it, and locate the C/C++ \ General panel. Open up the Additional Include Directories and delete all the entries, replacing them with:-

          $(OGRE_HOME)\include\OGRE
          $(OGRENEWT_HOME)\inc
          $(BOOST_HOME)
          $(NEWTON_HOME)\packages
          $(NEWTON_HOME)\packages\dCustomJoints
          $(NEWTON_HOME)\packages\dMath



          Now open up Linker\General, and open the Additional Library Directories. Remove all the ones there, and replace them with (for the debug configuration) :-

          $(OGRE_HOME)\lib\debug
          $(NEWTON_HOME)\Packages\Win32\debugDLL
          $(BOOST_HOME)\lib



          OKay, now you need to ensure that all the libraries you need are listed. So head to Linker\Input and make sure the Additional Dependencies are (at least):-

          ogremain_d.lib
          newton_d.lib
          dJointLibrary_d.lib
          ogreterrain_d.lib
          dmath_d.lib


          1. Under C/C++ Code Generation, ensure you've chosen "Multi-Threaded Debug DLL (/MDd)".
            [/*:m]
          2. Under Build Events\Post-Build Step, you may find some Copy instructions. Best to remove them. They tend to break.
            [/*:m]
          3. Lastly, open C/C++ \ Command Line, and add /Zm133 into the additional options.
            [/*:m]
          4. Okay, hit 'Build', and finger-crossed, OgreNewt should build with the latest Ogre (1.7.2) and Newton (2.33) releases.[/*:m][/list:u]

            If it worked, yay, now change the Project configuration for the "Release" configuration. Do all the same stuff for the debug Configuration, but take out the "_d" from the ends of library names, and change 'Debug' for 'Release' in the directory names. If it didn't work, then sorry, you're outta luck: Something must have changed, you've got your home folders not quite right, or I've goofed a step.

            Note: if you change an environment variable, you gotta close visual Studio and re-open it for the change to get picked up. Keep at it.



            Errors you may get when compiling OgreNewt

            1. Anything with (dllimport) in it means you're missing a library somewhere. Probably dmath_d.lib, or dJointLibrary_d.lib. Make sure you do the build Newton steps.[/*:m]
            2. Anything mentioning libboost_thread-vc90-mt-sgd-1_44 (NOTE: SGD) means you're trying to compile the library as a statically linked library. You *can* get the static version of the boost library if you hunt about, but it's best to just stick to making all your libs as DLLs. if it's just "GD", then you've not included the boost lib directory under 'Linker'.[/*:m]
            3. Anything saying that a symbol is already defined. uh oh, you're in the eternal trap of different compilation types. It means that two of your libraries are statically linked, and they both include a third one. When the project tries to import the second library, it finds all the symbols from the third already imported with the first! Eek. Either make sure you build the parent libs as DLLs, or only statically include one of them. This one can be a pain to debug for the novice.[/*:m]
            4. Anything saying you've got conflicting default libs. For the most part these warnings can be ignored. But if you have lots of these, and they're errors, it means that you've got two libraries trying to include two different versions of a third library. This is usually because one is static, the other dynamic. Usually this is the default windows C runtime libraries (the ones every project needs). To fix it, you'll have to make sure all your libraries, and your main project build the same way.[/*:m]
            5. You get a request for /Zmxxx. This is a strange one. Just go the C/C++ Command Line Additional Options box in the project, and pop in the suggested line. I used /Zm133 because it worked for me. You may need higher or lower.[/*:m][/list:u]



              You're all set.

              Create your new project, use the same include and library folders as mentioned above, but [important] remember to copy all the DLLs from Ogre\bin, Ogrenewt\lib and newton\packages\win32 to your project build output folder! without the DLLs in the same place as where your .exe gets compiled to, you'll end up with lots of dllimport errors. Why not create an empty project, all ready to go, and use it as a template for all your experiments?

              Good Luck!!



              Disclaimer: I am not an expert, I'm not a C++ guru, and I've been playing with Ogre and Newton for a grand total of a week. However, I managed to get it compiled, but couldn't find all of this information in one place, so thought it may help to put it all together. I apologise unreservedly if any of this is wrong. I know that there's probably much easier ways to do this, and I've probably broken some convention somewhere, but I now have working physics, so hey, I'm happy :D

Neecro

09-10-2011 15:16:07

Thanks for the guide... Can you help me to compile the demos? I get a linking error
1>OgreNewtonFrameListener.obj : error LNK2001: unresolved external symbol __imp__NewtonConvexCollisionCalculateInertialMatrix
1>OgreNewtonFrameListener.obj : error LNK2001: unresolved external symbol __imp__NewtonGetThreadsCount
1>OgreNewtonFrameListener.obj : error LNK2001: unresolved external symbol __imp__NewtonBodySetVelocity
1>OgreNewtonFrameListener.obj : error LNK2001: unresolved external symbol __imp__NewtonBodySetCentreOfMass

I dont get where it come from xd.

tod

10-10-2011 14:58:33

Add the necessary newton libs to your project.

rkeene

11-10-2011 21:42:50

Ok, some feedback is on order here, though I may get a lot of flack for this post. We are doing a project with Ogre3D and need a physics engine.
OgreNewt is the obvious one.

But...

After several days of trying to get it to work I think it would be easier to do custom physics instead.

1.) the download of OgreNewt2 is only available from Subversion and does not include precompiled libraries.
2.) The people that are developing both OrgeNewt and Newton think it is a 'simple matter' of downloading the code, do a quick compile and away you go. It is never that easy. You have to get exactly the right dependencies, compiler (Visual Studio 2008 or 2010?) and of course cMake. It takes hours and hours of broken builds etc.
3.) Newton does not even compile. There is a bad line in the current tip revision. Do the developers working in Newton even do a build before checking code in? Did I just happen to pull the tip revision on a bad day?
3.) Newton is precompiled more or less, but is missing dMath.dll and dMath.lib. How did that get left out? Do the developer every try a clean machine and install everything to see if it can build? Better yet, do they ever try running from prebuilt binaries? Also Newton has about 8 different builds, and only one or two complete at all.
4.) In OgreNewt there are paths in the VStudio projects that make no sense. Once again, try a clean machine download and build. Those paths may have been valid several years ago and the developer has a legacy directory structure, but really?
5.) The OgreNewt demo program crashes randomly. I don't want my game crashing randomly. That can cost tons of money a week after release.
6.) Once I got everything liking up with what little precompiled libraries there are, it simply crashes on start and never gets to the first line of main.

Any way, I apologize for the sarcastic tone here but I can't afford several days of wasted effort.

Recommendations:
1.) Get a PC with nothing installed and try to get OgreNewt and Newton building and working in it. Good luck. I bet there will be a lot of updates to Subversion after that.
2.) Build OgreNewt in both release and debug modes and publish the binaries.
3.) Build Newton in debug and release modes, and import the .h files and binaries into the OgreNewt subversion tree. Then one always has the exact matching revisions.
4.) Always assume that the developer using OgreNewt does not have the time, know how, nor patience to build from the source.

Due to the value of a physics engine I probably will be forced to us OgreNewt anyways and will spend whatever time it takes to get it working. Currently I have deleted some lines of code just to get it to build.

R. Keene - Sandswept Studios.

P.S. The same problems and attitudes prevail in CEGUI. We dropped it in favor of buttonGUI simply because buttonGUI is so simple to download and compile. And it is so small we can fix bugs in it and enhance it as needed.

tod

11-10-2011 22:14:27

Well, Newton is a one man's team effort so I guess some problems could be expected. On the bright side, Julio is very smart, while physics is concerned, and personally answers on the forum (if you see some of Sinbad's post regarding Ogre you can understand the value of the master). I don't really know why you are so bent on using Newton and not try something more mainstream like Bullet, for example.

OgreNewt is very, very poorly supported right now. Most of the add-on's seem to be poorly supported though, and that's understandable. But on the bright side, OgreNewt is actually very simple and with a little effort you can adapt it to your needs. I also have a pretty different version of OgreNewt for my hobby project. But once you understand it, and Newton, a bit adding stuff to it it's pretty much trivial. It's all about the right mindset, I'm using Newton and OgreNewt is just some nice to have abstraction layer that I must maintain myself instead of writing it from scratch.

rkeene

11-10-2011 22:27:11

Well, Newton is a one man's team effort so I guess some problems could be expected. On the bright side, Julio is very smart, while physics is concerned, and personally answers on the forum (if you see some of Sinbad's post regarding Ogre you can understand the value of the master). I don't really know why you are so bent on using Newton and not try something more mainstream like Bullet, for example.

OgreNewt is very, very poorly supported right now. Most of the add-on's seem to be poorly supported though, and that's understandable. But on the bright side, OgreNewt is actually very simple and with a little effort you can adapt it to your needs. I also have a pretty different version of OgreNewt for my hobby project. But once you understand it, and Newton, a bit adding stuff to it it's pretty much trivial. It's all about the right mindset, I'm using Newton and OgreNewt is just some nice to have abstraction layer that I must maintain myself instead of writing it from scratch.


Thanks for the tips. On way to judge a project is by how recent the posts are. Bullet is very active and current. I look into that.

nww02

14-10-2011 13:24:18

rkeen wrote>
After several days of trying to get it to work I think it would be easier to do custom physics instead.


Well, doing 2d or simplistic physics *is* far simpler to roll your own. Some GCSE maths and a bit of C++ programming, and you're all set. However, getting generalised phsyics running in a large environment with any kind of performance is darned tricky. Even if you spend a week getting OgreNewt + Newton working, you'll probably end up saving yourself time in the long run.

I'm not sure why you're having so many problems getting them to work. I'm a C#/SQL programmer, and managed to get Newton compiled within an hour, and OgreNewt within 2 days, from a standing start (installing VS2008 and re-learning C++ from 15 years ago at uni) using MSDN as a reference. Plain old VS2008Express (free), is all that's needed. Try following the recipe I sent in the OP. Be warned that in the newton distro, there's two VC90 projects. One works (packages), the other doesn't properly. To go from scratch to compiled up takes about 20 minutes if you've got everything downloaded properly.

One thing I won't do is disagree with you that only distributing source for the windows platform, and no compiled binaries is just plain dumb. It makes everyone's life harder, yes. Be warned, however, that OgreBullet is even more broken than OgreNewt. I came to the same conclusion as you, but travelled in the opposite direction. I may try bullet again once I have learned more about Newton.

Good Luck!

Daymo

02-11-2011 20:42:21

Thanks for this guide.
I followed it, but i get a link error when i try to use my compiled OgreNewt :
PremiereApplication.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: "public: __thiscall OgreNewt::Body::Body(class OgreNewt::World const *,class std::tr1::shared_ptr<class OgreNewt::Collision> const &,int)" (??0Body@OgreNewt@@QAE@PBVWorld@1@ABV?$shared_ptr@VCollision@OgreNewt@@@tr1@std@@H@Z) referenced in function "public: virtual void __thiscall PremiereApplication::createScene(void)" (?createScene@PremiereApplication@@UAEXXZ)
C:\Users\léo\Desktop\Programmation\Projets\Ogre\Debug\Ogre.exe : fatal error LNK1120: 1 unresolved external

Here there are my Additional Dependencies :
OgreMain_d.lib
OIS_d.lib
OgreNewt_d.lib
dContainers_d.lib
dJointLibrary_d.lib
dMath_d.lib
dScene_d.lib
newton_d.lib
tinyxml_d.lib

I can't see where is my error...

magnum696

02-01-2012 21:52:38

@nww02: I just wanted to say thanks for this. I was able to get OgreNewt compiled without any problems.