Reputation: 1254
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?
Upvotes: 1
Views: 147
Reputation: 917
You can link the lib (*.lib files) by following steps in Visual Studio:
Configuration Properties->Linker->AdditionalLibraryDirectories (e.g "C:\Users\abc\Documents\Visual Studio 2010\Projects\Test\Debug" )
Configuration Properties->Linker->Input->Additional Dependencies (e.g.: Test.lib; )
Upvotes: 1