Dani
Dani

Reputation: 15069

LNK2019 VS2012 error (unresolved external symbol)

I've made 2 projects: one is the provider, inside I've added a class DH:

using namespace std;
#ifdef PROVIDER_EXPORTS
#define DH_API __declspec(dllexport)
#else
#define DH_API __declspec(dllimport)
#endif
#include <iostream>

namespace Provider
{
    class DH
    {
    public:
        static DH_API std::string GetKey();
    };
}

and Imp:

#include "DH.h"

using namespace std;
namespace Provider
{


    std::string DH::GetKey()
    {

        return "KEY";
    }

}

when I dumpbin the dll I get:

?GetKey@DH@Provider@@SA?AV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@XZ = @ILT+10(?GetKey@DH@Provider@@SA?AV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@XZ)

On a new Project - the tester I include dh.h I've added the debug folder of the Provider project to the link directories

and I just call DH::GetKey but when I compile I get:

LNK2019: unresolved external symbol "__declspec(dllimport) public: static class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > __cdecl Provider::DH::GetKey(void)" (__imp_?GetKey@DH@Provider@@SA?AV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@XZ) referenced in function "long __stdcall WndProc(struct HWND__ *,unsigned int,unsigned int,long)" (?WndProc@@YGJPAUHWND__@@IIJ@Z)

What is wrong?

Upvotes: 0

Views: 875

Answers (2)

spiritwolfform
spiritwolfform

Reputation: 2293

You need to set up project dependencies or add your dll's .lib file to the tester project's lib input so it knows where to search for the imported functions

Upvotes: 1

Balog Pal
Balog Pal

Reputation: 17163

You miss an imported GetKey() function. There is a Project References section and you shall add the project that defines that function.

Upvotes: 0

Related Questions