为什么我们使用“__declspec(dllimport)”,当它看起来如此无用时?

Why do we use "__declspec(dllimport)" when it seems so useless?

有人告诉我,如果你想导出一个库,你需要使用 __declspec(dllexport),当有人使用这个库时,他或她需要添加 __declspec(dllimport)。但是今天发现没有必要

为什么我们需要 __declspec(dllimport)

来自documentation

Using __declspec(dllimport) is optional on function declarations, but the compiler produces more efficient code if you use this keyword. However, you must use __declspec(dllimport) for the importing executable to access the DLL's public data symbols and objects. Note that the users of your DLL still need to link with an import library.