0

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
πάντα ῥεῖ
  • 1
  • 13
  • 116
  • 190
sumit kang
  • 456
  • 1
  • 7
  • 20

2 Answers2

2

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 .

the_mandrill
  • 29,792
  • 6
  • 64
  • 93
0

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

msnw
  • 93
  • 7