How do I link a DLL to my project? error LNK2019: unresolved external symbol

前端 未结 3 1473
太阳男子
太阳男子 2021-02-05 20:35

I have a file foo.h that has various declarations for functions. All of these functions are implemented in a file foo.dll. However, when I include th

3条回答
  •  温柔的废话
    2021-02-05 20:59

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

    You are missing the step where you told the linker that it needs to link the .lib file. It needs to be added to the linker's Input + Additional Dependencies setting of your project. Or most easily done by writing the linker instruction in your source code:

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

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

提交回复
热议问题