連結器工具警告 LNK4248
'type' 的未解析 typeref Token (token) ;映像可能無法執行
類型在 MSIL 元資料中沒有定義。
當 MSIL 模組中只有類型正向宣告(使用 /clr 編譯)、MSIL 模組中參考該類型,以及 MSIL 模組與具有類型定義的原生模組連結的位置時,可能會發生LNK4248。
在此情況下,連結器會在 MSIL 元數據中提供原生類型定義,而這可能會提供正確的行為。
不過,如果轉送類型宣告是CLR類型,則連結器的原生類型定義可能不正確
如需詳細資訊,請參閱 /clr (Common Language Runtime 編譯)。
更正這個錯誤
- 在 MSIL 模組中提供類型定義。
範例
下列範例會產生LNK4248。 定義要解析的結構 A。
// LNK4248.cpp
// compile with: /clr /W1
// LNK4248 expected
struct A;
void Test(A*){}
int main() {
Test(0);
}
下列範例具有類型的正向定義。
// LNK4248_2.cpp
// compile with: /clr /c
class A; // provide a definition for A here to resolve
A * newA();
int valueA(A * a);
int main() {
A * a = newA();
return valueA(a);
}
下列範例會產生LNK4248。
// LNK4248_3.cpp
// compile with: /c
// post-build command: link LNK4248_2.obj LNK4248_3.obj
class A {
public:
int b;
};
A* newA() {
return new A;
}
int valueA(A * a) {
return (int)a;
}