How to link a DLL with my project? error LNK2019: unresolved external character

I have a foo.h file that has various declarations for functions. All these functions are implemented in the foo.dll file. However, when I include the .h file and try to use any of the functions, I get an error message:

 bar.obj : error LNK2019: unresolved external symbol SomeFunction 

therefore, it is obvious that no function implementations were found.

What do I need to do to help the compiler find the definitions in the DLL and associate them with the .h file?

I saw some things about __declspec(dllexport) and __declspec(dllimport) , but I still can't figure out how to use them.

+7
source share
3 answers

You should have received at least three files from the owner of the DLL. The DLL you will need at runtime, an .h file with declarations of exported functions, you already have. And the .lib file, the import library for the DLL. What the linker requires, so it knows how to add functions to the program import table.

You are missing the step where you told the linker that it needed to link the .lib file. It must be added to the configuration of the Input + Additional Dependencies linker of your project. Or the easiest way to do this is by writing the linker instructions in the source code:

 #include "foo.h" #pragma comment(lib, "foo.lib") 

Which works for MSVC but is not portable, but binding is never. Copy the .lib file to the project directory or specify the full path.

+8
source

I had a similar problem. The solution turned out that the DLL is 64 bits and the simple application is 32. I forgot to change it to x64 in Configuration Manager.

+6
source
  • You need to specify the keyword before the __declspec (dllexport) function definitions during dll build
  • You need to import or load the DLL file into the process memory.
  • You need to get the address of the function you want to use from this DLL.

Some useful links to get you started :: MSDN documentation , stack overflow

+3
source

All Articles