1
votes

I am trying following link to call dll function from a exe project in C++. In step 7 when I include the dll's lib file in the exe project through

TestExeProject->Properties->Linker->AdditionalLibraryDirectories, I am unable to compile the exe project. I am getting the following link error,

Error 1 error LNK2019: unresolved external symbol "__declspec(dllimport) public: __thiscall CTest::CTest(void)" (__imp_??0CTest@@QAE@XZ) referenced in function "protected: virtual int __thiscall CTestExeDlg::OnInitDialog(void)" (?OnInitDialog@CTestExeDlg@@MAEHXZ)

Error 2 error LNK2019: unresolved external symbol "__declspec(dllimport) int __cdecl fnTest(void)" (__imp_?fnTest@@YAHXZ) referenced in function "protected: virtual int __thiscall CTestExeDlg::OnInitDialog(void)" (?OnInitDialog@CTestExeDlg@@MAEHXZ)

The following issue I resolved by adding

#pragma comment(lib, "C:\\Users\\abc\\Documents\\Visual Studio 2010\\Projects\\Test\\Debug\\Test.lib")

But how to resolve this without adding this line but from the project properties?

1
Your code is trying to link to an external dll, look for "__declspec(dllimport)" in your code to see where. To do this this you need the header from the dll and the dll. The fact that you are getting this message indicates that you have the header, but cannot find the dll referenced.Shivaraj Bhat

1 Answers

1
votes

You can link the lib (*.lib files) by following steps in Visual Studio:

  1. Configuration Properties->Linker->AdditionalLibraryDirectories (e.g "C:\Users\abc\Documents\Visual Studio 2010\Projects\Test\Debug" )

  2. Configuration Properties->Linker->Input->Additional Dependencies (e.g.: Test.lib; )