what does __declspec(dllimport) really mean?

前端 未结 4 966
温柔的废话
温柔的废话 2020-11-29 16:41

I saw the Qt source code like this:

class Q_CORE_EXPORT QBasicAtomicInt
{
public:
...
};

Which Q_CORE_EXPORT macro defines lik

4条回答
  •  再見小時候
    2020-11-29 17:27

    __declspec(dllexport) tells the compiler to inform the linker that these symbols need to be placed in the export table (when compiling the .dll). When compiling the program that links with the .dll, __declspec(dllimport) tells the compiler to produce a rip-relative absolute register-indirect indirect call (which the linker will fill resolve to point to the import table) rather than the usual rip-relative register-direct indirect call instruction to an undefined function (which, as it can't modify the instruction, the linker inserts the relative address of a thunk and then creates the thunk, inside which it places the rip-relative absolute register-indirect indirect call to the function pointer in the import table). This is a code size and speed optimisation. It is the import library .lib that tells the linker which symbols will be imported and is used as a guide to create the import table and create any necessary thunks in the .text segment.

    https://docs.microsoft.com/en-us/cpp/build/importing-function-calls-using-declspec-dllimport?view=vs-2019 https://docs.microsoft.com/en-us/cpp/build/importing-data-using-declspec-dllimport?view=vs-2019 https://stackoverflow.com/a/4490536/7194773

提交回复
热议问题