2012-01-14 167 views
-1

我收到了幾個error LNK2019: unresolved external symbol錯誤,但它們不是由於dll s,lib s或OO錯誤,因爲在每個其他StackOverflow文章中都有關於此鏈接錯誤的信息。Visual Studio C++ 2010鏈接錯誤

代碼:

https://github.com/mcandre/fgdump/tree/master/cachedump

跟蹤:

1>------ Build started: Project: cachedump, Configuration: Release Win32 ------ 
1>LINK : warning LNK4075: ignoring '/INCREMENTAL' due to '/OPT:ICF' specification 
1>cachedump.obj : error LNK2019: unresolved external symbol "void __cdecl rc4_crypt(struct rc4_state *,unsigned char *,int)" ([email protected]@[email protected]@[email protected]) referenced in function "unsigned long __cdecl DumpCache(void)" ([email protected]@YAKXZ) 
1>cachedump.obj : error LNK2019: unresolved external symbol "void __cdecl rc4_setup(struct rc4_state *,unsigned char *,int)" ([email protected]@[email protected]@[email protected]) referenced in function "unsigned long __cdecl DumpCache(void)" ([email protected]@YAKXZ) 
1>cachedump.obj : error LNK2019: unresolved external symbol "void __cdecl md5_finish(struct md5_context *,unsigned char * const)" ([email protected]@[email protected]@[email protected]) referenced in function "unsigned long __cdecl DumpCache(void)" ([email protected]@YAKXZ) 
1>cachedump.obj : error LNK2019: unresolved external symbol "void __cdecl md5_update(struct md5_context *,unsigned char *,unsigned long)" ([email protected]@[email protected]@[email protected]) referenced in function "unsigned long __cdecl DumpCache(void)" ([email protected]@YAKXZ) 
1>cachedump.obj : error LNK2019: unresolved external symbol "void __cdecl md5_starts(struct md5_context *)" ([email protected]@[email protected]@@Z) referenced in function "unsigned long __cdecl DumpCache(void)" ([email protected]@YAKXZ) 
1>C:\Users\andrew\Desktop\src\fgdump\cachedump\Release\cachedump.exe : fatal error LNK1120: 5 unresolved externals 
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ========== 

ABC

+0

你是不是新來的StackOverflow。難道你不知道這種問題會很快關閉嗎? – 2012-01-14 19:18:24

+0

這個問題不是重複的;它與LNK2019上的其他帖子有很大不同。根本原因是非常不同的,因爲此代碼不使用'dll's,不使用''lib's,並且不使用OO。 – mcandre 2012-01-14 19:32:46

+0

我沒有說它是重複的。這只是一個不適合SO的問題,因爲你已經給了我們大量的代碼並要求找出你的錯誤。發生問題的最小例子發生了什麼? – 2012-01-14 19:38:29

回答

1

.c文件由clC代碼編譯,而.cpp文件編譯爲C++代碼。由於CC++中的符號定義不同,所以您的C++代碼不能從C代碼中看到功能。

使用extern "C"包裝的標題,或更好地使用同一種語言對整個項目

爲了extern "C"包裝使用下面的模板

#ifdef __cplusplus 
extern "C" 
{ 
#endif 

//put C-function declarations here  

#ifdef __cplusplus 
} 
#endif 
+0

謝謝。不幸的是,使用它並不能解決我的問題,奇怪的是,項目中的其他代碼鏈接很好,而無需使用extern聲明。 – mcandre 2012-01-15 03:06:34

+0

_應該已經解決了這個問題。 _Did_你試過了嗎?如果是這樣,你嘗試了什麼?原因之一是,其他代碼會鏈接正常,因爲該代碼是「C++」,它被「C++」代碼使用。 – Lol4t0 2012-01-15 08:46:52

+0

請下載並打開Visual Studio解決方案。你會親眼看到添加extern不會有幫助。 – mcandre 2012-01-15 14:16:01