Problems creating a DLL - extern keyword troubles

Started by
5 comments, last by deadstar 15 years, 6 months ago
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.

"The right, man, in the wrong, place, can make all the dif-fer-rence in the world..." - GMan, Half-Life 2

A blog of my SEGA Megadrive development adventures: http://www.bigevilcorporation.co.uk

Advertisement
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.
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.
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.

"The right, man, in the wrong, place, can make all the dif-fer-rence in the world..." - GMan, Half-Life 2

A blog of my SEGA Megadrive development adventures: http://www.bigevilcorporation.co.uk

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?

"The right, man, in the wrong, place, can make all the dif-fer-rence in the world..." - GMan, Half-Life 2

A blog of my SEGA Megadrive development adventures: http://www.bigevilcorporation.co.uk

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.
I don't like the name std::vector. I'd be happy if it was std::array.
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.

"The right, man, in the wrong, place, can make all the dif-fer-rence in the world..." - GMan, Half-Life 2

A blog of my SEGA Megadrive development adventures: http://www.bigevilcorporation.co.uk

This topic is closed to new replies.

Advertisement