• Advertisement
Sign in to follow this  

Linker Error - Can't Find The Cause.

This topic is 619 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 Guys,

I have created a basic framework that I want to turn in to a DLL to use with another program.

In the original project (which is a normal Win32 project so I could test the engine), the headers are located in 'engine.h' and the implementation is in 'engine.cpp'.

This all works fine and everything runs ok.

I have now made a second project (for the DLL project) and have set the include path to the first project and have included 'engine.h'. And I have mad e test function to make sure it all compiles ok.
 
#pragma once
#include"d:\engine\engine.h"

#define fn_export extern "C" __declspec (dllexport)

int test()
{
	Engine e;
	return 0;
}
It compiles but throws linker errors complaining that it cant find the constructor and destructor for the class (implemented in 'engine.cpp')
 

Error LNK2001 unresolved external symbol "public: __thiscall Engine::Engine(void)" (??0Engine@@QAE@XZ)
Error LNK2001 unresolved external symbol "public: __thiscall Engine::~Engine(void)" (??1Engine@@QAE@XZ)


But the cpp files are in the same directory as the header file 'engine.h'

So I am a bit confused here.

Any help would be aweseome!

Thanks in advance :) Edited by DarkRonin

Share this post


Link to post
Share on other sites
Advertisement

Just having files in the same directory means nothing. Are the relevant .cpp files added to both projects?


Nope.

I'll do that now.

So how do SDK's work then, if you only have to add the '.h' files?

Share this post


Link to post
Share on other sites
So how do SDK's work then, if you only have to add the '.h' files?

 

You don't. You also have to link the appropriate library files (unless the SDK in question is contained entirely in headers). In some cases this is hidden from you somewhat, through various means, but it still has to happen. 

Edited by Josh Petrie

Share this post


Link to post
Share on other sites

Well, on some compilers you can link libraries with #pragma directives. Ex: #pragma comment(lib, "library_name.lib") on MSVC. Personally I hate it when libraries do it.

Share this post


Link to post
Share on other sites

Using pragma link directives aren't a bad thing, especially if you want to cross compile your code and a project file isn't going to work for you (project files only work for the ide they're designed for, so specifying link directives in them turns out to actually be very bad.) Best way yet is to specify linker instructions in your make file, but sometimes a pragma is more convenient. It comes down to competently commenting your code.

Share this post


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

  • Advertisement