連結器工具錯誤 LNK2020
未解析的權杖 'token'
類似于未定義的外部錯誤,不同之處在于參考是透過中繼資料。 在中繼資料中,必須定義所有函式和資料。
解決方式:
定義遺漏的函式或資料,或
包含已定義遺漏函式或資料的物件檔案或程式庫。
範例
下列範例會產生LNK2020。
// LNK2020.cpp
// compile with: /clr /LD
ref struct A {
A(int x); // LNK2020
static int f(); // LNK2020
};
// OK
ref struct B {
B(int x) {}
static int f() { return 0; }
};
如果您建立 Managed 範本類型的變數,但不會同時具現化類型,也會發生LNK2020。
下列範例會產生LNK2020。
// LNK2020_b.cpp
// compile with: /clr
template <typename T>
ref struct Base {
virtual void f1() {};
};
template <typename T>
ref struct Base2 {
virtual void f1() {};
};
int main() {
Base<int>^ p; // LNK2020
Base2<int>^ p2 = gcnew Base2<int>(); // OK
};