Using dllimport in place of dllexport

前端 未结 1 1496
死守一世寂寞
死守一世寂寞 2021-01-25 13:53

I seem to be able to use __declspec(dllexport) and __declspec(dllimport) interchangeably when building my dll in Visual Studio 2015. I would have thoug

相关标签:
1条回答
  • 2021-01-25 14:13

    If you look carefully, you will see that your DLL project compiles with warnings, like this:

     c:\yourproject\add.cpp(3,1):warning C4273: 'add': inconsistent dll linkage
    

    The compiler knows that you are up to no good. A dllimport function should not be defined, only declared. So when the compiler sees the definition, it assumes dllexport should be used instead, because that's the most reasonable resolution of the mistake.

    It is a good practice to treat compiler warnings as errors.

    0 讨论(0)
提交回复
热议问题