1

I have a c++ application which is using a DLL. Now, I want to access a method from that DLL in my application. But, compiler is giving me "unresolved external symbol" error as it is unable to find the method even though my function in DLL is exported properly. When I include .lib file path of respective DLL in my application's additional dependencies, the error got resolved and application is working properly.

But, some people told me that I should not include .lib file when I am using a DLL. It is just like statically linking the DLL.

1) Is inclusion of .lib file when using DLLs in application, is good practice or not ?

To avoid this .lib file inclusion and to avoid calling GetProcAddess for every exportable method, they suggested me to write some wrapper class and create a virtual method to access the method from the class in DLL. I didn't understand this approach.

2) Can anybody explain why I need the wrapper class and how this abstract class can provide me the function I required ?

Thanks in advance.

  • Bro code. Rule number 42: Bro tells you what's the best, but you are in doubt. Read the [docs](https://msdn.microsoft.com/en-us/library/windows/desktop/ms682589%28v=vs.85%29.aspx) and prove Bro wrong, so he could write better software. – Ivan Aksamentov - Drop May 07 '16 at 11:28

2 Answers2

1

1) Is inclusion of .lib file when using DLLs in application, is good practice or not?

According to msdn you are required to link to .lib files when using dll. Consideration of good or bad practice comes in when you have choices. Which you don't have here.

they suggested me to write some wrapper class and create a virtual method to access the method from the class in DLL.

Well if you create a wrapper class then you will have to link that wrapper class with the dll and that will bring you in the same place again.

army007
  • 551
  • 4
  • 20
0

Inclusion of .lib file when using dll is used by all the shared libraries I've used on Windows.

It's important to understand that, on Windows platform, not all the libraries with .lib extension are static. Here is a discussion that explains how to understand if your .lib library is a static library or an import library.

Community
  • 1
  • 1
Francesco Argese
  • 626
  • 4
  • 11