編譯 C 寫的 COM 組件時,鏈接器報 undefined reference to IID_IUnknown,雖然頭文件已包含定義。
IID_IUnknown 是 GUID 變量,定義在 uuid.lib (MSVC) 或 libuuid.a (MinGW) 中。EXTERN_C const IID IID_IUnknown;,實際定義在庫文件,需顯式鏈接。| 編譯器 | 鏈接參數 |
|---|---|
| MSVC (cl.exe) | 加入 uuid.lib(通常在 Windows SDK lib 目錄) |
| MinGW (gcc) | 加入 -luuid 或 -lole32 |
| CMake | target_link_libraries(your_target uuid) |
regsvr32 註冊時,確保 DLL 導出 DllGetClassObject、DllCanUnloadNow、DllRegisterServer、DllUnregisterServer 四大入口。