-1

I'm getting several error LNK2019: unresolved external symbol errors, but they're not due to dlls, libs, or OO errors as in every other StackOverflow post about this link error.

Code:

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

Trace:

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)" (?rc4_crypt@@YAXPAUrc4_state@@PAEH@Z) referenced in function "unsigned long __cdecl DumpCache(void)" (?DumpCache@@YAKXZ)
1>cachedump.obj : error LNK2019: unresolved external symbol "void __cdecl rc4_setup(struct rc4_state *,unsigned char *,int)" (?rc4_setup@@YAXPAUrc4_state@@PAEH@Z) referenced in function "unsigned long __cdecl DumpCache(void)" (?DumpCache@@YAKXZ)
1>cachedump.obj : error LNK2019: unresolved external symbol "void __cdecl md5_finish(struct md5_context *,unsigned char * const)" (?md5_finish@@YAXPAUmd5_context@@QAE@Z) referenced in function "unsigned long __cdecl DumpCache(void)" (?DumpCache@@YAKXZ)
1>cachedump.obj : error LNK2019: unresolved external symbol "void __cdecl md5_update(struct md5_context *,unsigned char *,unsigned long)" (?md5_update@@YAXPAUmd5_context@@PAEK@Z) referenced in function "unsigned long __cdecl DumpCache(void)" (?DumpCache@@YAKXZ)
1>cachedump.obj : error LNK2019: unresolved external symbol "void __cdecl md5_starts(struct md5_context *)" (?md5_starts@@YAXPAUmd5_context@@@Z) referenced in function "unsigned long __cdecl DumpCache(void)" (?DumpCache@@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

mcandre
  • 22,868
  • 20
  • 88
  • 147
  • You are not new to stackoverflow. Don't you know that this kind of question will be closed in no time? – Armen Tsirunyan Jan 14 '12 at 19:18
  • This question is NOT a duplicate; it differs significantly from other posts on LNK2019. The root cause is remarkably different because this code does NOT use `dll`s, does NOT use `lib`s, and does NOT use OO. – mcandre Jan 14 '12 at 19:32
  • I didn't say it's a duplicate. It's just a question not fit for SO, because you've given us tons of code and ask to find your error. What happened to minimal example that reproduces the problem? – Armen Tsirunyan Jan 14 '12 at 19:38

1 Answers1

1

.c files are compiled by cl as C code, while .cpp files are compiles as C++ code. Due to difference of symbols definitions in C and C++ code your C++ code can't see functions from C code.

Use extern "C" wrapper in headers, or better use same language for the whole project

To make extern "C" wrapper use the following template

#ifdef __cplusplus
extern "C"
{
#endif

//put C-function declarations here    

#ifdef __cplusplus
}
#endif
Lol4t0
  • 12,444
  • 4
  • 29
  • 65
  • Thanks. Unfortunately, using this does not solve my problem, and strangely, other code within the project links just fine without using the extern declarations. – mcandre Jan 15 '12 at 03:06
  • That _should_ have fixed the issue. _Did_ you tried that? If so, _what_ did you try? Of cause, other code will links OK, because that code is `C++` and it is used by `C++` code. – Lol4t0 Jan 15 '12 at 08:46
  • Please download and open the Visual Studio solution. You will see for yourself that adding the externs does not help. – mcandre Jan 15 '12 at 14:16
  • @mcandre, sorry for 2 day absence, I had no time to answer. I think, you did something wrong, because, of cause I checked your project before making such an assertion. Both _renaming_ `.c` to `.cpp` and making `extern "C"` _does_ work for me. And it _should_ work for you, as it is no magic. – Lol4t0 Jan 17 '12 at 16:49