sumit kang
sumit kang

Reputation: 476

Unresolved External Symbol Error 2001

I am getting error LNK2001 when i try to use my dll project in another project.

Code for my header File is

#ifdef VIZFUNCTIONSDLL_EXPORTS
#define VIZFUNCTIONSDLL_API __declspec(dllexport) 
#else
#define VIZFUNCTIONSDLL_API __declspec(dllimport) 
#endif

namespace VizFunctions
{
  class SUMCLASS
 {
     public:
        static VIZFUNCTIONSDLL_API double Test(double a);

 };
}

Code for my Source file is

// VizFunctions.cpp : Defines the exported functions for the DLL application.

//

#include "stdafx.h"
#include "VizFunctions.h"
#include <stdexcept>

namespace VizFunctions
{

 double SUMCLASS::Test(double a)
 {
   return a;
 }

}

Error message

Error 13 error LNK2019: unresolved external symbol "public: static double 
    __cdecl VizFunctions::SUMCLASS::Test(double)" 
    (?Test@SUMCLASS@VizFunctions@@SANN@Z) referenced in function "public: 
    int __thiscall CRectangle::PlugInNewGeom(int)" (?PlugInNewGeom@CRectangle@@QAEHH@Z) 
C:\Program Files (x86)\vizrt\Viz3\plugin\src\examples\rectangle\Rectangle.obj SampleRectangle

Upvotes: 0

Views: 514

Answers (2)

msnw
msnw

Reputation: 93

Looks like you didn't include static library which is generated when you build dll to your new project.

Upvotes: 0

the_mandrill
the_mandrill

Reputation: 30862

You will see this error if you aren't linking against the Import Library for the dll. The Import Library is a bit of glue code that will load the DLL for you and map the exported dll functions automatically.

Ensure that your DLL project is creating an import library in Properties -> Linker -> Advanced -> Import Library

Import library setting

If you add the dll project as a dependency of your executable (rather than just the dll) then this will automatically link against the import library and resolve the link error. If you don't have it as a dependency then you will need to explicitly add the import library to Linker -> Input -> Additional Dependencies .

Upvotes: 2

Related Questions