Sign in to follow this  
Graham11

Wild Magic as DLL Question

Recommended Posts

Hi all, I'm using WildMagic for maths in an SDK I'm developing for gesture recognition. Now I need my SDK in DLL form, where previously static libs were fine. I've rebuilt Wild Magic as a DLL by changing the MS vcproj 'Configuration Type' to Dynamic Link Library (from Static Library) and adding WML_DLL_EXPORT to the preprocessor defs. Now I get a few LNK2001 Link errors relating to some static consts (e.g public: static float const Wml::Math<float>::MAX_REAL). I don't know much about DLLs, so I created a test program. It compiles and runs only as long as I keep the // comment in place. Can anyone help? Thanks, Graham
#include <stdio.h>
#include <WmlMath.h>
#include <WmlEigen.h>

int main()
{
	double result;
	result = Wml::Mathd::Sqrt(25.0);
	Wml::Eigend E(3);
	//result = Wml::Mathd::MAX_REAL;
	return 0;
}


Share this post


Link to post
Share on other sites
From my experience, creating dll's is not just case of changing the build settings. Firstly, its common to create a .def file that defines the functions, classes and fields that your dll will export. Secondly, the library code is quite different, for example you need to specifty before the funcs, classes & fields that they can be exported, eg __declspec( dllimport ) declarator

Finally, your code will need to load the library, unlike a static lib, this involves creating CALLBACK pointers to all of the exported functions, and casting them to functions in your app.

I'm sorry if this is not the answer to your problem, but these are things I was unaware of when experimenting with dlls.

Good Luck
David

Share this post


Link to post
Share on other sites
Linker error as a result of static variables is simply because you haven't provided a definition for it:


class Foo
{
public:
static int SomeInt;
};


This will give you an unresolved external error as you haven't actually defined the variable, all you need to do is this:


class Foo
{
public:
static int SomeInt;
};

//required
Foo::SomeInt;


Simply adding Foo::SomeInt; will remove the error, you could also provide a value for it at the same time if you wish.

I suspect that the source code will already contain these definitions of static constants so make sure you are including the relevant files for your project.

Share this post


Link to post
Share on other sites
Thanks for the help.

It works. I simply had to include WML_DLL_IMPORT in the preprocessor defs of the calling app. I found that out from the Wild Magic release notes.

What a laugh, for an hour there I even failed to notice I'd copied the (WML_DLL_IMPORT) define from the pdf release notes, not picking up the underscores. So I had WML DLL IMPORT defined!

You've gotta laugh.
[crying]

Cheers,
Graham

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this