LNK2019 problem

前端 未结 4 1770
面向向阳花
面向向阳花 2021-01-06 08:02

I have a LNK2019 problem when trying to use some DLL in my project.

Details:

  1. I have a DLL project called dll1; that compiled just fine (using __d
4条回答
  •  鱼传尺愫
    2021-01-06 08:04

    Just a guess:

    If you include the header from dll1 in the dll2 project and in that header you use the __declspec(dllexport)) you tell the linker that dll2 is also exporting these classes that actually are meant to be imported by dll2 and so is missing classes definition.

    So one would ususally use a definition like this.

    #ifdef DLL1_EXPORTS
    #define DLLEXPORT __declspec(dllexport)
    #else
    #define DLLEXPORT __declspec(dllimport)
    #endif
    
    class DLLEXPORT A
    {
        //...
    

    This construction makes sure, the dll1 definitions are exported when the header is used in dll1 and imported when used inside dll2 project. All you need is the macro DLL1_EXPORT to be defined when dll1 is compiled. The project settings for dll1 is usually a good place.

    Another approach is to have 2 different headers, one for building dll1 and a second to be used together wit dll1's lib (without any __declspec(dllexport)).

提交回复
热议问题