2011-07-27 92 views
0
enter code here 
//Prj1 

//main1.cpp 

#include "stdafx.h" 
#include <iostream> 
#include <conio.h> 
#include "head1.h" 

using namespace std; 

void main() 
{ 
cout<<display(); 
cout<<"welcome"; 
_getch(); 
} 


//head1.h 
char* display(void); 

//head1.cpp 

#include "stdafx.h" 
#ifdef _cplusplus 
extern "C" { 
#endif 

char* display(void) 
{ 
return("head1 functuion called\n"); 
} 

#ifdef _cplusplus 
} 
#endif 



//prj2 
enter code here 
//main2.cpp 

#include "stdafx.h" 
#include <iostream> 
#include <conio.h> 
#include "head1.h" 

using namespace std; 

void main() 
{ 
cout<<display(); 
cout<<"welcome prj 2"; 
getch(); 
} 

這些是一個解決方案中的兩個項目。另外我已經添加prj1的路徑作爲額外的包括prj2 siarecory。編造着解決方案,同時連接,我得到以下錯誤:未解析的外部符號鏈接程序時出錯:

1>鏈接... 1> main2.obj:錯誤LNK2019:無法解析的外部符號 「的char * __cdecl顯示(無效)」(顯示器@@ YAPADXZ)在函數_main中引用 1> C:\ Documents and Settings \ 469515 \ My Documents \ NFC HAL SDK v2.2 \ Nfc \ comps \ phHalNfc \ EX1 \ prj1 \ Debug \ prj2.exe:致命錯誤LNK1120: 1周無法解析的外部

任何人可以幫助我認爲:

回答

1

刪除此行:

#ifdef _cplusplus 
extern "C" { 
#endif 

從CPP文件。

或者將相同的行添加到頭文件中。

+0

仍存在同樣的問題。 – Durgesh

+0

你做了什麼?從兩處刪除了「extern」C「',或者添加到兩個地方。嘗試重建所有。 – Ajay

+0

我刪除它並重建所有。它顯示錯誤。然後我再次添加到這兩個地方並重建解決方案。 – Durgesh

相關問題