Sign in to follow this  
deadstar

Problems creating a DLL - extern keyword troubles

Recommended Posts

Hi, I'm trying to compile my engine into a .lib + .dll ready to start a game. After much Googling and a few nights of tearing my hair out, I think I'm down to the last few niggles. This is the linker error I'm getting when I try and compile a project using my .lib file:
main.obj : error LNK2001: unresolved external symbol "class sym::CEngine * sym::Engine" (?Engine@sym@@3PAVCEngine@1@A)

And here are the relevant parts of the Engine.h:
#ifndef SYM_API
#define SYM_API __declspec(dllexport)
#endif

class SYM_API CEngine
	{
 		public:
			CEngine();

			//Init and shutdown the engine
			bool Init();
			void ShutDown();

...

extern SYM_API CEngine* Engine;

And the Engine.cpp:
CEngine* Engine = new CEngine();

Secondly, all I can find in the Debug folder is the .lib file. Where is there DLL? My project is set to compile a DLL and not a static lib. Thanks in advance for any hints and tips.

Share this post


Link to post
Share on other sites
My first guess would be that your CEngine constructor was not defined anywhere for that linker error.

I also don't believe the DLL would be built until the compile is successful.

I'm at work, so I can't test my theories right now.

Share this post


Link to post
Share on other sites
Hi, I dont know much about dllimport/dllexport, but here's how I use it. First I have a macro a bit like yours, but in a seperate file:

#ifdef COMPILE_DLL
# define OZY_DLL __declspec(dllexport)
#else
# define OZY_DLL __declspec(dllimport)
#endif

You do the right thing to export your classes, but the application using the dll needs to import it. Meaning that the class should be defined with dllexport when compiling the dll, and with dllimport when compiling the game. The macro above is usefull to do that in a single header.

Share this post


Link to post
Share on other sites
Quote:
Original post by KOzymandias
Hi, I dont know much about dllimport/dllexport, but here's how I use it. First I have a macro a bit like yours, but in a seperate file:

#ifdef COMPILE_DLL
# define OZY_DLL __declspec(dllexport)
#else
# define OZY_DLL __declspec(dllimport)
#endif

You do the right thing to export your classes, but the application using the dll needs to import it. Meaning that the class should be defined with dllexport when compiling the dll, and with dllimport when compiling the game. The macro above is usefull to do that in a single header.


Thank you, I'll give that a go.

Share this post


Link to post
Share on other sites
Ok, that compiles and links fine (both the .lib and the game using it), but now I'm having troubles excecuting it.

I get the error:


This application has failed to start because symmetry.exe was not found. Re-installing the application may fix it.


If anything, I was expecting it to complain about a missing symmetry.dll (which I have still yet to find...)

Any clues?

Share this post


Link to post
Share on other sites
IMHO your project is built as DLL but just with .exe file extension. There might be symmetry.exe in the Debug directory, which is actually a DLL.

PS: You can specify target file name in Configuration Properties\Linker\General\Output File.

Share this post


Link to post
Share on other sites
Quote:
Original post by muse1987
IMHO your project is built as DLL but just with .exe file extension. There might be symmetry.exe in the Debug directory, which is actually a DLL.

PS: You can specify target file name in Configuration Properties\Linker\General\Output File.


Thank you, that worked.

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