自定义控件编译不了的错误
在创建一个自定义的类时,vc6 中编译一下报错
错误信息
Deleting intermediate files and output files for project 'TEST3 - Win32 Uni Debug'.
--------------------Configuration: TEST3 - Win32 Uni Debug-------------------- Building resources from Test3_caption.rss perl -S epocrc_ide6.pl -I "\WORK\TEST3\DATA" -I "\WORK\TEST3\GROUP" -I "\WORK\TEST3\INC" -I- -I "\WORK\TEST3\GROUP" -I "\Symbian\8.0a\S60_2nd_FP2_SC\EPOC32\INCLUDE" -DLANGUAGE_SC -u "\WORK\TEST3\DATA\Test3_caption.rss" -o"\Symbian\8.0a\S60_2nd_FP2_ SC\EPOC32\RELEASE\WINS\UDEB\Z\SYSTEM\APPS\TEST3\TEST3_CAPTION.rSC" -h"\WORK\TEST3\DATA\TEST3_CAPTION.rs~" -t"\Symbian\8.0a\S60_2nd_FP2_SC\EPOC32\BUILD\WORK\TEST3\GROUP\TEST3\WINS\UDEB" echo this is a dummy output file > "\Symbian\8.0a\S60_2nd_FP2_SC\EPOC32\RELEASE\WINS\UDEB\Z\SYSTEM\APPS\TEST3\TEST3_CAPTION.rSC.dummy" perl -S ecopyfile.pl "\WORK\TEST3\DATA\TEST3_CAPTION.rs~" "\Symbian\8.0a\S60_2nd_FP2_SC\EPOC32\INCLUDE\TEST3_CAPTION.RSG" del "\WORK\TEST3\DATA\TEST3_CAPTION.rs~" Building resources from Test3.rss perl -S epocrc_ide6.pl -I "\WORK\TEST3\DATA" -I "\WORK\TEST3\GROUP" -I "\WORK\TEST3\INC" -I- -I "\WORK\TEST3\GROUP" -I "\Symbian\8.0a\S60_2nd_FP2_SC\EPOC32\INCLUDE" -DLANGUAGE_SC -u "\WORK\TEST3\DATA\Test3.rss" -o"\Symbian\8.0a\S60_2nd_FP2_SC\EPOC3 2\RELEASE\WINS\UDEB\Z\SYSTEM\APPS\TEST3\TEST3.rSC" -h"\WORK\TEST3\DATA\TEST3.rs~" -t"\Symbian\8.0a\S60_2nd_FP2_SC\EPOC32\BUILD\WORK\TEST3\GROUP\TEST3\WINS\UDEB" echo this is a dummy output file > "\Symbian\8.0a\S60_2nd_FP2_SC\EPOC32\RELEASE\WINS\UDEB\Z\SYSTEM\APPS\TEST3\TEST3.rSC.dummy" perl -S ecopyfile.pl "\WORK\TEST3\DATA\TEST3.rs~" "\Symbian\8.0a\S60_2nd_FP2_SC\EPOC32\INCLUDE\TEST3.RSG" del "\WORK\TEST3\DATA\TEST3.rs~" Compiling... Test3.uid.cpp Test3app.cpp Test3appui.cpp Test3container.cpp Test3document.cpp SimpleControl.cpp C:\Work\Test3\src\SimpleControl.cpp(39) : warning C4100: 'aType' : unreferenced formal parameter C:\Work\Test3\src\SimpleControl.cpp(39) : warning C4100: 'aKeyEvent' : unreferenced formal parameter Generating Code... Doing first-stage link by name link.exe @C:\Users\zziss\AppData\Local\Temp\nma03676. Creating library \Symbian\8.0a\S60_2nd_FP2_SC\EPOC32\BUILD\WORK\TEST3\GROUP\TEST3\WINS\UDEB\TEST3.lib and object \Symbian\8.0a\S60_2nd_FP2_SC\EPOC32\BUILD\WORK\TEST3\GROUP\TEST3\WINS\UDEB\TEST3.exp TEST3CONTAINER.obj : error LNK2001: unresolved external symbol "public: static class CSimpleControl * __cdecl CSimpleControl::NewLC(class TRect const &)" (?NewLC@CSimpleControl@@SAPAV1@ABVTRect@@@Z) \Symbian\8.0a\S60_2nd_FP2_SC\EPOC32\BUILD\WORK\TEST3\GROUP\TEST3\WINS\UDEB\TEST3.APP : fatal error LNK1120: 1 unresolved externals NMAKE : fatal error U1077: 'link.exe' : return code '0x460' Stop. if exist "\Symbian\8.0a\S60_2nd_FP2_SC\EPOC32\BUILD\WORK\TEST3\GROUP\TEST3\WINS\UDEB\TEST3.exp" del "\Symbian\8.0a\S60_2nd_FP2_SC\EPOC32\BUILD\WORK\TEST3\GROUP\TEST3\WINS\UDEB\TEST3.exp" Stopped the build by removing the export object, if present, because the pre-link stage failed Linking... LINK : fatal error LNK1104: cannot open file "\Symbian\8.0a\S60_2nd_FP2_SC\EPOC32\BUILD\WORK\TEST3\GROUP\TEST3\WINS\UDEB\TEST3.exp" 执行 link.exe 时出错. TEST3.APP - 1 error(s), 0 warning(s) |
其实这个错误信息 主要是这里 public: static class CSimpleControl * __cdecl CSimpleControl::NewLC(class TRect const &)"
这个项目是通过 appWizard 生成的,所有的都是默认操作
后来终于找到这个问题的解决方法了
1. 在生成时,不要把工程的 dsw 文件生成到和 mmp 文件相同的位置,也就是在向导的最后一步选择第二个单选框“Generate files to epoc32\build folder”
2. 生成完成后 bldmake bldfiles ,然后 abld makefiles vc6 ,生成工作空间文件,
3. 添加类,注意,添加类时要看一下头文件及代码文件保存的路径是否正确(头文件在 inc 目录,代码文件在 src 目录)
4. 编辑 mmp 文件,把这个类的 cpp 文件添加到 source 里
5. 把这个控件引用到容器类中
6. 编译会报上面的错误信息
7. 这里去 epoc32\build 目录下,删除这个工程文件目录
8. 重新 bld 文件及 abld vc6的工程文件
9. 再次打开工程,编译,没有错误
具体这个错误是由哪里引起的就不知道了,也没有找出来
关于这个问题我到论坛上的提问
我做了一个最简单的练习,通过 app 向导生成一个项目 然后添加一个类 头文件 Code: #include <coecntrl.h> class CSimpleControl : public CCoeControl { public: static CSimpleControl* NewLC(const TRect& aRect); static CSimpleControl* NewL(const TRect& aRect); void SizeChanged(); void ConstructL(const TRect& aRect); CSimpleControl(); virtual ~CSimpleControl(); TKeyResponse OfferKeyEventL(const TKeyEvent& aKeyEvent,TEventCode aType); TInt CountComponentControls() const; private: void Draw(const TRect &aRect) const; }; Code: CSimpleControl::CSimpleControl() { } CSimpleControl::~CSimpleControl() { } void CSimpleControl::ConstructL(const TRect &aRect) { CreateWindowL(); SetRect(aRect); ActivateL(); } void CSimpleControl::Draw(const TRect &aRect) const { CWindowGc& gc = SystemGc(); gc.SetPenStyle(CGraphicsContext::ENullPen); gc.SetPenColor(KRgbRed); gc.SetBrushColor(KRgbDarkBlue); gc.SetBrushStyle(CGraphicsContext::ESolidBrush); gc.DrawRect(aRect); } TKeyResponse CSimpleControl::OfferKeyEventL(const TKeyEvent &aKeyEvent, TEventCode aType) { return EKeyWasNotConsumed; } void CSimpleControl::SizeChanged() { } TInt CSimpleControl::CountComponentControls() const { return 1; } CSimpleControl* CSimpleControl::NewLC(const TRect &aRect) { CSimpleControl* self = new (ELeave) CSimpleControl(); CleanupStack::PushL(self); self->ConstructL(aRect); return self; } CSimpleControl* CSimpleControl::NewL( const TRect& aRect ) { CSimpleControl* self = CSimpleControl::NewLC(aRect); CleanupStack::Pop(self); return self; } 定义为 Code: private: //data CEikLabel* iLabel; // example label CEikLabel* iToDoLabel; // example label CSimpleControl* iSimple; }; Code: void CSimpleContainer::ConstructL(const TRect& aRect) { CreateWindowL(); iLabel = new (ELeave) CEikLabel; iLabel->SetContainerWindowL( *this ); iLabel->SetTextL( _L("Example View") ); iToDoLabel = new (ELeave) CEikLabel; iToDoLabel->SetContainerWindowL( *this ); iToDoLabel->SetTextL( _L("Add Your controls\n here") ); iSimple = CSimpleControl::NewLC(aRect); iSimple->SetContainerWindowL(*this); SetRect(aRect); ActivateL(); } 错误信息 Code: Deleting intermediate files and output files for project 'SIMPLE - Win32 Uni Debug'. --------------------Configuration: SIMPLE - Win32 Uni Debug-------------------- Building resources from Simple_caption.rss perl -S epocrc_ide6.pl -I "\WORK\SIMPLE\DATA" -I "\WORK\SIMPLE\GROUP" -I "\WORK\SIMPLE\INC" -I- -I "\WORK\SIMPLE\GROUP" -I "\Symbian\8.0a\S60_2nd_FP2_SC\EPOC32\INCLUDE" -DLANGUAGE_SC -u "\WORK\SIMPLE\DATA\Simple_caption.rss" -o"\Symbian\8.0a\S60_2n d_FP2_SC\EPOC32\RELEASE\WINS\UDEB\Z\SYSTEM\APPS\SIMPLE\SIMPLE_CAPTION.rSC" -h"\WORK\SIMPLE\DATA\SIMPLE_CAPTION.rs~" -t"\Symbian\8.0a\S60_2nd_FP2_SC\EPOC32\BUILD\WORK\SIMPLE\GROUP\SIMPLE\WINS\UDEB" echo this is a dummy output file > "\Symbian\8.0a\S60_2nd_FP2_SC\EPOC32\RELEASE\WINS\UDEB\Z\SYSTEM\APPS\SIMPLE\SIMPLE_CAPTION.rSC.dummy" perl -S ecopyfile.pl "\WORK\SIMPLE\DATA\SIMPLE_CAPTION.rs~" "\Symbian\8.0a\S60_2nd_FP2_SC\EPOC32\INCLUDE\SIMPLE_CAPTION.RSG" del "\WORK\SIMPLE\DATA\SIMPLE_CAPTION.rs~" Building resources from Simple.rss perl -S epocrc_ide6.pl -I "\WORK\SIMPLE\DATA" -I "\WORK\SIMPLE\GROUP" -I "\WORK\SIMPLE\INC" -I- -I "\WORK\SIMPLE\GROUP" -I "\Symbian\8.0a\S60_2nd_FP2_SC\EPOC32\INCLUDE" -DLANGUAGE_SC -u "\WORK\SIMPLE\DATA\Simple.rss" -o"\Symbian\8.0a\S60_2nd_FP2_SC \EPOC32\RELEASE\WINS\UDEB\Z\SYSTEM\APPS\SIMPLE\SIMPLE.rSC" -h"\WORK\SIMPLE\DATA\SIMPLE.rs~" -t"\Symbian\8.0a\S60_2nd_FP2_SC\EPOC32\BUILD\WORK\SIMPLE\GROUP\SIMPLE\WINS\UDEB" echo this is a dummy output file > "\Symbian\8.0a\S60_2nd_FP2_SC\EPOC32\RELEASE\WINS\UDEB\Z\SYSTEM\APPS\SIMPLE\SIMPLE.rSC.dummy" perl -S ecopyfile.pl "\WORK\SIMPLE\DATA\SIMPLE.rs~" "\Symbian\8.0a\S60_2nd_FP2_SC\EPOC32\INCLUDE\SIMPLE.RSG" del "\WORK\SIMPLE\DATA\SIMPLE.rs~" Compiling... Simple.uid.cpp Simpleapp.cpp Simpleappui.cpp Simplecontainer.cpp SimpleControl.cpp C:\Work\Simple\group\SimpleControl.cpp(39) : warning C4100: 'aType' : unreferenced formal parameter C:\Work\Simple\group\SimpleControl.cpp(39) : warning C4100: 'aKeyEvent' : unreferenced formal parameter Simpledocument.cpp Generating Code... Doing first-stage link by name link.exe @C:\DOCUME~1\QIJIAN~1\LOCALS~1\Temp\nma05404. Creating library \Symbian\8.0a\S60_2nd_FP2_SC\EPOC32\BUILD\WORK\SIMPLE\GROUP\SIMPLE\WINS\UDEB\SIMPLE.lib and object \Symbian\8.0a\S60_2nd_FP2_SC\EPOC32\BUILD\WORK\SIMPLE\GROUP\SIMPLE\WINS\UDEB\SIMPLE.exp SIMPLECONTAINER.obj : error LNK2001: unresolved external symbol "public: static class CSimpleControl * __cdecl CSimpleControl::NewLC(class TRect const &)" (?NewLC@CSimpleControl@@SAPAV1@ABVTRect@@@Z) \Symbian\8.0a\S60_2nd_FP2_SC\EPOC32\BUILD\WORK\SIMPLE\GROUP\SIMPLE\WINS\UDEB\SIMPLE.APP : fatal error LNK1120: 1 unresolved externals NMAKE : fatal error U1077: 'link.exe' : return code '0x460' Stop. if exist "\Symbian\8.0a\S60_2nd_FP2_SC\EPOC32\BUILD\WORK\SIMPLE\GROUP\SIMPLE\WINS\UDEB\SIMPLE.exp" del "\Symbian\8.0a\S60_2nd_FP2_SC\EPOC32\BUILD\WORK\SIMPLE\GROUP\SIMPLE\WINS\UDEB\SIMPLE.exp" Stopped the build by removing the export object, if present, because the pre-link stage failed Linking... LINK : fatal error LNK1104: cannot open file "\Symbian\8.0a\S60_2nd_FP2_SC\EPOC32\BUILD\WORK\SIMPLE\GROUP\SIMPLE\WINS\UDEB\SIMPLE.exp" 执行 link.exe 时出错. Creating browse info file... SIMPLE.APP - 1 error(s), 0 warning(s) |