Unresolved external __fastcall 錯誤訊息 |
答題得分者是:aftcast
|
cubi
初階會員 發表:56 回覆:94 積分:35 註冊:2002-04-15 發送簡訊給我 |
各位先進好,小弟是bcb新手
小弟想把一些自訂函數放在一個cpp裡 但確出現了以下錯誤訊息 小弟已有己mylib add 到project裡,也有include了 感謝各位先進,感激不盡 [Linker Error] Unresolved external '__fastcall mytest::Test1()' referenced from C:\DOCUMENTS AND SETTINGS\USER\桌面\TEST\UNIT1.OBJ 原始碼如下 mylib.h [code cpp] #include #ifndef mylibH #define mylibH #endif namespace mytest { void __fastcall Test1(); } [/code] mylib.cpp [code cpp] #pragma hdrstop #include "mylib.h" #pragma package(smart_init) void __fastcall Test1() { ShowMessage("a"); } [/code] Unit1.cpp [code cpp] #include #pragma hdrstop #include "Unit1.h" #include "mylib.h" //--------------------------------------------------------------------------- #pragma package(smart_init) #pragma resource "*.dfm" TForm1 *Form1; using namespace mytest; //--------------------------------------------------------------------------- __fastcall TForm1::TForm1(TComponent* Owner) : TForm(Owner) { } void __fastcall TForm1::Button1Click(TObject *Sender) { mytest::Test1(); } [/code] 編輯記錄
cubi 重新編輯於 2008-11-19 13:23:07, 註解 無‧
|
herbert2
尊榮會員 發表:58 回覆:640 積分:894 註冊:2004-04-16 發送簡訊給我 |
===================引 用 cubi 文 章=================== 各位先進好,小弟是bcb新手 小弟想把一些自訂函數放在一個cpp裡 但確出現了以下錯誤訊息 小弟已有己mylib add 到project裡,也有include了 感謝各位先進,感激不盡 [Linker Error] Unresolved external '__fastcall mytest::Test1()' referenced from C:\DOCUMENTS AND SETTINGS\USER\桌面\TEST\UNIT1.OBJ 原始碼如下 mylib.h [code cpp] #include #ifndef mylibH #define mylibH #endif namespace mytest { void __fastcall Test1(); } [/code] mylib.cpp [code cpp] #pragma hdrstop #include "mylib.h" #pragma package(smart_init) void __fastcall Test1() { ShowMessage("a"); } [/code] Unit1.cpp [code cpp] #include #pragma hdrstop #include "Unit1.h" #include "mylib.h" //--------------------------------------------------------------------------- #pragma package(smart_init) #pragma resource "*.dfm" TForm1 *Form1; // using namespace mytest; //--------------------------------------------------------------------------- __fastcall TForm1::TForm1(TComponent* Owner) : TForm(Owner) { } void __fastcall TForm1::Button1Click(TObject *Sender) { // mytest::Test1(); Test1(); } [/code] |
aftcast
站務副站長 發表:81 回覆:1485 積分:1763 註冊:2002-11-21 發送簡訊給我 |
[code cpp] void __fastcall mytest::Test1() //這樣寫才是正確的! 要有namespace的解析在定義。不是只有宣告需要而已! { ShowMessage("a"); } [/code] 如果你沒加上mytest:: 來定義,那麼compiler就會認定Test1( )是全域的函式。當然,若你呼叫時使用不含解析子的Test1( ),則先去比對全域是否有定義。剛好有定義,所以也pass,但這不是你想要的。你希望在指定的namespace下使用的話,定義也要加解析子。 你錯誤訊息的過程是,compiler去找一個namespace叫mytest的區塊,然後去找Test1( ),找到了…(因為你在h檔上有「宣告」),所以compiler成功。然而到了link的時候,卻找不到Test1( )的進入點。因為,沒有「定義」! 你定義的是全域函式,而非mytest下的函數。故link error。
------
蕭沖 --All ideas are worthless unless implemented-- C++ Builder Delphi Taiwan G+ 社群 http://bit.ly/cbtaiwan
編輯記錄
aftcast 重新編輯於 2008-11-20 01:36:12, 註解 無‧
|
cubi
初階會員 發表:56 回覆:94 積分:35 註冊:2002-04-15 發送簡訊給我 |
本站聲明 |
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。 2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。 3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇! |