# Problems creating a DLL - extern keyword troubles

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

## 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 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 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 on other sites
Quote:
 Original post by KOzymandiasHi, 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)#endifYou 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 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 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 on other sites
Quote:
 Original post by muse1987IMHO 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.

1. 1
2. 2
3. 3
4. 4
Rutin
18
5. 5

• 12
• 12
• 9
• 12
• 37
• ### Forum Statistics

• Total Topics
631421
• Total Posts
2999997
×