c++dllshared-libraries

Confusion about the linking method of dynamic libraries like d3d11


As far as I know, we need __declspec(dllexport) to export symbols to import libraries (.lib files), which are required by implicit linking.
When I glanced at d3d11.h, I found that all functions don't have __declspec.

But how to explain the existing import library d3d11.lib? Could implicit linking works without __declspec(dllimport) in headers when we try to call functions in them.

Could implicit linking works without __declspec(dllimport) in headers when we try to call functions in them?


Solution

  • This applies to Win .dlls (when working with VStudio).

    There are 2 stages:

    1. Create the .dll (which will export symbols)

    There are multiple ways (3) to export symbols from a .dll. Check:

    1. [MS.Learn]: Exporting from a DLL Using __declspec(dllexport)

    2. [MS.Learn]: Exporting from a DLL Using DEF Files

    3. [MS.Learn]: /EXPORT (Exports a Function)

    Might also want to read:

    2. Use (symbols from) the .dll

    This is typically when building a client for the (above) .dll (could be an app or another .dll).

    According to [MS.Learn]: Import into an application using __declspec(dllimport) (emphasis is mine):

    Using __declspec(dllimport) is optional on function declarations, but the compiler produces more efficient code if you use this keyword.