2012-01-14 162 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