Visual Studio C++ 2010链接错误
问题描述:
我收到了几个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
答
.c
文件由cl
为C
代码编译,而.cpp
文件编译为C++
代码。由于C
和C++
中的符号定义不同,所以您的C++
代码不能从C
代码中看到功能。
使用extern "C"
包装的标题,或更好地使用同一种语言对整个项目
为了extern "C"
包装使用下面的模板
#ifdef __cplusplus
extern "C"
{
#endif
//put C-function declarations here
#ifdef __cplusplus
}
#endif
你是不是新来的StackOverflow。难道你不知道这种问题会很快关闭吗? – 2012-01-14 19:18:24
这个问题不是重复的;它与LNK2019上的其他帖子有很大不同。根本原因是非常不同的,因为此代码不使用'dll's,不使用''lib's,并且不使用OO。 – mcandre 2012-01-14 19:32:46
我没有说它是重复的。这只是一个不适合SO的问题,因为你已经给了我们大量的代码并要求找出你的错误。发生问题的最小例子发生了什么? – 2012-01-14 19:38:29