我創建了一個* .bpl項目BPL_A它包含一個TForm子類,說TForm_Sub。C++ builder包導出鏈接錯誤
頭文件Form_Sub.h就像是以下幾點:
class PACKAGE TForm_Sub : public TForm
{
...
};
extern PACKAGE TForm_Sub* Form_Sub;
源文件Form_Sub.cpp就像是以下幾點:
TForm_Sub* Form_Sub;
__fastcall TForm_Sub::TForm_Sub(TComponent* Owner)
{
...
}
我創建另一個* .bpl項目BPL_B動態創建TForm_Sub實例。
class PACKAGE SomeClass
{
public:
TForm* CreateUI(const AnsiString& name);
};
#include "Form_Sub.h"
TForm* SomeClass::CreateUI(const AnsiString& name)
{
if(name == xxx)
{
if(Form_Sub != NULL)
{
Form_Sub = new TForm_Sub(owner);
}
return Form_Sub;
}
}
我將BPL_A.bpi添加到BPL_B的需要部分。但是,構建BPL_B時出現以下鏈接錯誤。
[ILINK32 Error] Error: Export SomeClass::CreateUI() in module xxx.OBJ references __fastcall TForm_Sub::TForm_Sub() in unit BPL_A]Form_Sub.
我找不出什麼是缺失。
非常感謝,@manlio。我在SomeClass .cpp文件前添加'#pragma package(smart_init)指令',它可以工作。 – odomchen