Advertisement Jump to content
Sign in to follow this  

Unity HOWTO: Export class from static library.

This topic is 4889 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi people, I'm sorry I have tried searching the forum but did not find any answers to my question. So here I am, with the question... This is how my static library looks like, simple and there's no compilation or linker errors in it. _EXPORT has been defined only in the static lib project, not in the client (EXE) project.
#ifndef _EXPORT
#define _CLASS_TYPE __declspec(dllimport)
#define _CLASS_TYPE __declspec(dllexport)
class _CLASS_TYPE CMyClass

void SomeFunction(void);

When I tried to use "SomeFunction" in the client, it links fine and things work well. There are linking problems if I were to do a "CMyClass a;", complaining about unresolved class constructor/destructor. I have checked both project settings, including threading mode (both Multithreaded Debug DLL). The only difference I noticed was static library built with "Use Standard Windows Libraries", while the client "Use MFC in a Shared DLL". Is that the cause of the problem? Thanks in advance for any help! [Edited by - HaywireGuy on August 28, 2005 3:03:42 AM]

Share this post

Link to post
Share on other sites
What I do with my static lib(math)is simply create it as a static library project, build the project, take the .lib generated move it to a libs folder I have setup, this folder is setup as an additional place to look for libs in the IDE and I simply #include the headers in the .exe project and it works fine. I think __declspec(dll...) is for importing/exporting classes, etc to a DLL... if this is being built as a static lib it should be fine if your linker is finding the .lib you generated when building the .exe. Im thinking your last sentence could cause problems, try making them the same.

Share this post

Link to post
Share on other sites
Thanks NumberXaero, yah I agree the MFC thing looks very suspicious. In that
case I might need to make a new project with MFC settings, if that's necessary.
I'll give that a try tomorrow and keep you posted. Thanks again.

Share this post

Link to post
Share on other sites
Yes! I got it to work, with two changes:

1. Change "Use Standard Windows Libraries" to "Use MFC in a Shared DLL".
2. Remove __declspec(dllimport) and __declspec(dllexport) because this is a static library.

Thanks again NumberXaero!

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using, you agree to our community Guidelines, Terms of Use, and Privacy Policy. is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!