Box2D problem

Started by
4 comments, last by archaos90 15 years ago
Hey, I have ran into this problem surely so many others have, yet I can't find any answers elsewhere so I turn to you now. I want to use Box2D in my project and I'm using the latest Bloodshed Dev-C++ version. All tutorials say nothing about that I can't use that so I'll stick to my favorite IDE. I had a hard time building Box2D itself, but I had to resort to using Visual C++ 2008 Express. Then, I have the library built and all and now I want to be building stuff with it too. I assume I'm supposed to use the lonely Box2D.h include file that came with the source of the library. When I did, it wanted a lot of other header files which led to me having to use the whole source to the library just to compile mine. I know this isn't right, since I just built a static library earlier with the source, so I now realize I'm doing something wrong. Question is, what am I doing wrong and what am I supposed to do? P.s. please don't come with the simple answer "use vc++, it rocks". I love my current IDE and I actually hate VC++. It's bloated and tries to write its own rules regarding how to program. Again, help would be appreciated! D.s
Advertisement
// These include files constitute the main Box2D API#include "../Source/Common/b2Settings.h"#include "../Source/Collision/Shapes/b2CircleShape.h"#include "../Source/Collision/Shapes/b2PolygonShape.h"#include "../Source/Collision/Shapes/b2EdgeShape.h"#include "../Source/Collision/b2BroadPhase.h"#include "../Source/Dynamics/b2WorldCallbacks.h"#include "../Source/Dynamics/b2World.h"#include "../Source/Dynamics/b2Body.h"#include "../Source/Dynamics/Contacts/b2Contact.h"#include "../Source/Dynamics/Joints/b2DistanceJoint.h"#include "../Source/Dynamics/Joints/b2GearJoint.h"#include "../Source/Dynamics/Joints/b2LineJoint.h"#include "../Source/Dynamics/Joints/b2MouseJoint.h"#include "../Source/Dynamics/Joints/b2PrismaticJoint.h"#include "../Source/Dynamics/Joints/b2PulleyJoint.h"#include "../Source/Dynamics/Joints/b2RevoluteJoint.h"#include "../Source/Dynamics/Controllers/b2BuoyancyController.h"#include "../Source/Dynamics/Controllers/b2ConstantForceController.h"#include "../Source/Dynamics/Controllers/b2ConstantAccelController.h"#include "../Source/Dynamics/Controllers/b2GravityController.h"#include "../Source/Dynamics/Controllers/b2TensorDampingController.h"


Quote:I assume I'm supposed to use the lonely Box2D.h include file that came with the source of the library. When I did, it wanted a lot of other header files which led to me having to use the whole source to the library just to compile mine.


I just downloaded Box2D and opened up Box2D.h
The above is the file in it's almost-entirety. How do you expect to use Box2D without any of those include files?
The static library you compiled provides access to the compiled functions/methods the library uses. You need to use all those include files to get the function/method's signatures.
I couldn't really tell that from your post, but I assume you were able to make it work anyway
Okey, but now the compile complains about some undeclared variable in the Box2D library. I went to check it out and I found these lines:

inline bool b2IsValid(float32 x){#ifdef _MSC_VER	return _finite(x) != 0;#else	return finite(x) != 0;#endif}


These lines leads me to believe that the preprocessor checks if I am trying to compile with VC++, which is not the case, so it defaults to the other of its two supported compiler enviroments (Xcode and CodeBlocks). This should be fixable, but how? Any ideas?


p.s

This is what the compile said:

In file included from include/Box2D/include/../Source/Collision/Shapes/b2Shape.h:22,                 from include/Box2D/include/../Source/Collision/Shapes/b2CircleShape.h:22,                 from include/Box2D/include/Box2D.h:36,                 from main.cpp:16:include/Box2D/include/../Source/Collision/Shapes/../../Common/b2Math.h: In function `bool b2IsValid(float32)':include/Box2D/include/../Source/Collision/Shapes/../../Common/b2Math.h:63: error: `finite' undeclared (first use this function)include/Box2D/include/../Source/Collision/Shapes/../../Common/b2Math.h:63: error: (Each undeclared identifier is reported only once for each function it appears in.)make.exe: *** [obj/main.o] Error 1Execution terminated

I just set up a project to use Box2D (in VC++ 2008 Express but this should apply anywhere) - here's how to get started:

1. Unzip Box2D
2. Build Box2D using either the provided VS solution files or the makefiles
3. Add the Libraries directory (I believe that is what it was called) from the directory containing Source and Includes directories to the list of places for you linker to look for libraries in
4. Link Box2d.lib or Box2d.a
5. Add the Includes directory to your compiler's places to search for included files
6. Include box2d.h into your files

Your project should build and you should be on your way with Box2D.
Nevermind. I solved the problem. Now I have the basis for a platform Super Mario Bros.-kind of game I'm making, but with realistic physics. I'm having a story and everything planned. Just need someone good at drawing sprites now.

The game is called 'The Scientist' and is about, suprisingly, a scientist. He's intentionally unnamed, but not mute. The adventure will start with him creating a Time Machine which he wants to use to save his son who was killed a few years before the game starts. The device does not work as intended and he ends up in various periods of time. In contrast to many other games there is no villain who will play some sort of the last boss. It's an adventurous puzzle-solving game with a few RPG-elements. Time to time dialogs (in text) will occur where the scientist will give some humuorus comments, especially math- and science-oriented jokes. If you remember the first Lost Vikings game? Well, something in the style of that.

The gameplay will mainly be about solving puzzles but enemies will come in your way. Your only weapon is physics. Well actually, not the theory of physics. I mean the real deal. Throwing boxes, rocks.. make trees fall down on your enemies etc. You will have use of your brain, trust on that. I'll come back again when I have some alpha version ready - or whenever I run into some seemingly unsolvable problem and ask you for help.
Quote:Original post by Colin Jeanne
I just set up a project to use Box2D (in VC++ 2008 Express but this should apply anywhere) - here's how to get started:

1. Unzip Box2D
2. Build Box2D using either the provided VS solution files or the makefiles
3. Add the Libraries directory (I believe that is what it was called) from the directory containing Source and Includes directories to the list of places for you linker to look for libraries in
4. Link Box2d.lib or Box2d.a
5. Add the Includes directory to your compiler's places to search for included files
6. Include box2d.h into your files

Your project should build and you should be on your way with Box2D.


Well, not really. For MinGW-based compilers you'll need to manually patch the b2Math.h file in the "Source/Common"-directory. The first path to do is
#include <cmath>

to

#include <math.h>

The second thing to change is

inline bool b2IsValid(float32 x){#ifdef _MSC_VER	return _finite(x) != 0;#else	return finite(x) != 0;#endif}


which should be patched into this:

inline bool b2IsValid(float32 x){#ifdef _MSC_VER	return _finite(x) != 0;#else	return isfinite(x) != 0;#endif}


With those changes done plus what you said will have it work. At least it did for me.

This topic is closed to new replies.

Advertisement