Bullet and Namespaces

Post Reply
peterk
Posts: 14
Joined: Mon Dec 15, 2008 6:52 pm

Bullet and Namespaces

Post by peterk »

Hi Erwin,

I know in the past the use of namespaces has been rejected as adding unnecessary complications for library users but I'd like to explain a use case where this is proving a problem.

One of the advantages of using Bullet is being able to modify the library itself to support specific requirements. However, if a modified Bullet is used to build a plugin for another application (eg. Houdini) this will cause issues if another plugin then links against it's own static build of Bullet. In the forthcoming Houdini 12, Sidefx are packaging their own Bullet based plugin, and the concern is this will clash with our own build.

In an ideal world, it would be possible to specify the namespace used by bullet as a compile time option so that multiple differing builds can safely coexist. So something like:

#ifdef BTUSENAMESPACE
#define BTNAMESPACE Bullet
#define BTNAMESPACEBEGIN namespace BTNAMESPACE {
#define BTNAMESPACEEND }
#define BTNAMESPACEUSING using namespace BTNAMESPACE;
#else
#define BTNAMESPACEBEGIN
#define BTNAMESPACEEND
#define BTNAMESPACEUSING
#endif

Then surround all headers with BTNAMESPACEBEGIN/BTNAMESPACEND and put BTNAMESPACEUSING at the top of implementation files. That way the default behaviour would be to still not use namespaces but it would also be simple to create a safely namespaced custom build.

Unfortunately the layout of some of the headers at the moment mean it won't be simple to automatically add this with a script (predeclaring bullet classes before includes), so there would need to be some tidying up first. I'd like to know if this is an approach you'd be interested in adopting.

Cheers.
User avatar
Erwin Coumans
Site Admin
Posts: 4221
Joined: Sun Jun 26, 2005 6:43 pm
Location: California, USA
Contact:

Re: Bullet and Namespaces

Post by Erwin Coumans »

Separate (dynamic loaded) plugins that each link statically link against its own version of Bullet shouldn't cause a problem.

Nevertheless, I don't mind having an optional namespace, as long as it is switched off by default.

Do you have time to provide a patch, based on the latest svn trunk? If so, please use a single namespace (no nested namespaces etc) and use the google tracker.
Thanks!
Erwin
peterk
Posts: 14
Joined: Mon Dec 15, 2008 6:52 pm

Re: Bullet and Namespaces

Post by peterk »

Hi Erwin,

thanks for the response. I investigated this further and it looks like the gcc option -fvisibility=hidden will do what I need. If I have further problems I'll definitely look into providing a patch.

Cheers,
Pete
Post Reply