Linker Error - Can't Find The Cause.

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

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 on other sites
Just having files in the same directory means nothing. Are the relevant .cpp files added to both projects?

Share on other sites

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

1. 1
2. 2
3. 3
Rutin
15
4. 4
khawk
14
5. 5
frob
12

• 9
• 11
• 11
• 23
• 12
• Forum Statistics

• Total Topics
633662
• Total Posts
3013231
×