September 8th, 2008, 10:58 PM
Need help on linking error in C code!!
I am working in XP, Visual C++ v6 doing maintenance on existing report preparing codes. I am new to C++ language and to C/C++ programming. I have a linking error and would appreciate some expert help.
:\Documents and Settings\IVarma\Desktop\kunda\Modcode.cpp(916) : warning C4508: 'main' : function should return a value; 'void' return type assumed
Modcode.obj : error LNK2001: unresolved external symbol "int __cdecl open_cluster(void)" (?open_cluster@@YAHXZ)
Modcode.obj : error LNK2001: unresolved external symbol _BTRV@24
Modcode.obj : error LNK2001: unresolved external symbol "char * dbpath" (?dbpath@@3PADA)
Modcode.obj : error LNK2001: unresolved external symbol _fatal
Modcode.obj : error LNK2001: unresolved external symbol _set_multi_defaults
Modcode.obj : error LNK2001: unresolved external symbol "char * __cdecl get_option(void)" (?get_option@@YAPADXZ)
Modcode.obj : error LNK2001: unresolved external symbol "int __cdecl new_decode_cluster(char *,char (* const))" (?new_decode_cluster@@YAHPADQAY13GE@D@Z)
Debug/Modcode.exe : fatal error LNK1120: 7 unresolved externals
Error executing link.exe.
September 8th, 2008, 11:52 PM
The errors all appear to be unresolved dependencies, which means that there are functions and external variables which you are referring to in your code, but which aren't getting included in the list of libraries to link into the program. Where are open_cluster(), get_options(), etc. from? Are they in a library you are using, or another source file which is part of what you're compiling?
Are you compiling from the command line or in the Visual C++ editor? If the former, can you post the command line you're calling it with, or the make file you're using to build if you have one? If it is the latter, are you certain that the library or object file for these functions is in your project file?
September 9th, 2008, 05:17 AM
If it is the latter you can get the same information by holding CTRL and clicking the HTML build log link in the build "Output" window. Post that text.
Originally Posted by Schol-R-LEA
September 9th, 2008, 09:08 AM
September 9th, 2008, 09:12 PM
Hmmn, yes, that is illuminating fnord. Looking at the code posted in the first message just adds new questions, however.
First off, is this same code which you are referring to, or is this (as I suspect) a different module version of the program? Modcode.cpp is a C++ program, of course, but if you are simply trying to compile the existing C code as a C++ program, you will almost certainly run into issues of some kind, as already mentioned elsewhere. The error messages, and especially the function prototypes quoted which are defined with the __cdecl modifier, indicate that you're trying to call on a library written in C. Do you actually have this library, already compiled to object code in C?
Is the new program (Modcode.cpp) a modified version of the code posted earlier (as the name implies)? Can you tell us something about what you're trying to accomplish with it? The original code is 15 years old, and the last listed modification was ten years ago; given that it is financial service software, do the business rules it encodes even still apply, and how do you need to alter them if not? Also, this is a copyrighted, business-related program; did you have permission to post this code publicly from the owners?
I might add, as a personal comment, that IMAO this is some truly wretched C code. You have my sympathies in trying to maintain it. Some broad refactoring is in order, I think.
I'll leave it to others to spork you for cross-posting. Suffice it to say that you shouldn't do it again, mmmm'kay?