|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
Stay one step ahead of the competition. Evaluate and give feedback
on some of the hottest web development tools on the market today.
Make your opinion heard! Click
Here
|
|
#1
|
|||
|
|||
|
error LNK2001 when compiling under VS 6.0
Hello everyone... this is my first time to this website, so please forgive me if I do something incorrectly...
Anyhow, I am working on my final project for my C-Languag 1 programming class... for the project, I need to build a custom library and 4 test programs to test the functionality of the library... I am currently still working on getting my various functions to work and pass pointers to one another... Anyhow, I run into a problem that I can't figure out... I keep getting the error message: Code:
Project_Library.obj : error LNK2001: unresolved external symbol "void __cdecl S_VAL_S(char,struct Options *)" (?S_VAL_S@@YAXDPAUOptions@@@Z) Project_Library.obj : error LNK2001: unresolved external symbol "void __cdecl S_VAL_I(char,struct Options *)" (?S_VAL_I@@YAXDPAUOptions@@@Z) Project_Library.obj : error LNK2001: unresolved external symbol "void __cdecl S_FLAG(char)" (?S_FLAG@@YAXD@Z) Debug/Project_1.exe : fatal error LNK1120: 3 unresolved externals Error executing link.exe. I currently have 4 files (main.cpp, main.h, proj_lib.cpp, proj_lib.h)... the function prototypes for S_VAL_S & S_VAL_I are declared in the proj_lib.h file, while the definitions for these functions are in the proj_lib.cpp file... here is what they look like: Code:
//////////////////////////////////////////////////// //proj_lib.h //////////////////////////////////////////////////// #ifndef PROJ_LIB_H #define PROJ_LIB_H #include "main.h" void CLAP(int count, char** value, struct Options *); // Command Line Argument Process void CLAE(); // Command Line Argument Error void S_FLAG(char tag); // Single Character Check/Change State Function void S_VAL_I(char tag, struct Options *); // Single Character Value(int) Function void S_VAL_S(char tag, struct Options *); // Single Character Value(string) Function void W_FLAG(char tag); // Word Check/Change State Function void W_VAL_I(char* tag, int i_param); // Word Value(int) Function void W_VAL_S(char* tag, string s_param); // Word Value(string) Function #endif Code:
////////////////////////////////////////////////////
//proj_lib.cpp
////////////////////////////////////////////////////
#include "proj_lib.h"
// COMMAND LINE ARGUMENT PROCESS
// parses command line arguments passed from main function
// and determines appropriate secondary function(s) to call
void CLAP(int count, char** value, struct Options * p_opt)
{
// Determine if command line has proper number of arguments or call CLAE()
if ( (count < MIN) || (count > MAX) )
{
CLAE();
}
// Loop through all arguments on command line
for (int i = 1; i < count; i++)
// Determine if command line beings with '-' or '--' and has unary
// or binary arguments, then call appropriate secondary function
if ( (value[i][0] == '-') && (strlen (value[i]) == 2) )
{
// if # of args is = to current index then call S_FLAG
if ( count == i )
{
S_FLAG(value[i][1]);
}
// if # of args is > current index & the first char
// value of next index = '-' then call S_FLAG
else if ( (count > i) && (value[i + 1][0] = '-') )
{
S_FLAG(value[i][1]);
}
// if # of args is > current index & the first char
// value of next index != '-' then call S_VAL
else if ( (value[i][0] == '-') && (value[i + 1][0] != '-') )
{
// if next index char value is numeric, convert to integer
// and call S_VAL using integer conversion as 2nd parameter
p_opt->s_param = *(value[i + 1]);
p_opt->i_param = atoi(p_opt->s_param.c_str());
if ( p_opt->i_param != NULL)
{
S_VAL_I(*(value[i + 1]), p_opt);
}
else
{
S_VAL_S(*(value[i + 1]), p_opt);
}
}
}
// other misc. code
}
// COMMAND LINE ARGUMENT ERROR
// displays an error message and usage syntax, then exits
void CLAE()
{
// Display error & usage messages
cout << "*** ERROR ***" << endl << endl;
cout << "Usage: filename [-option]/[--option] {numeric/integer value}" << endl << endl;
cout << "Please use [-h]/[--help] to display list of acceptable options" << endl << endl;
// Exit program
exit(-1);
}
// SINGLE CHARACTER CHECK/CHANGE STATE FUNCTION
// sets or clears (make true or false) variable which
// corresponds to the TAG value passed from command line
void S_FLAG(char* tag)
{
// compare tag value(s) against list of changeable options and then
// process changes based upon predefined choices of customization
cout << *tag << endl;
}
// SINGLE CHARACTER VALUE FUNCTION (int)
// accepts a numeric parameter and sets the variable associated
// with that specific option TAG equal to the parameter value
void S_VAL_I(char* tag, struct Options * p_opt)
{
// set variable equal to parameter value
cout << *tag << p_opt->i_param << endl;
}
// SINGLE CHARACTER VALUE FUNCTION (string)
// accepts a string parameter and sets the variable associated
// with that specific option TAG equal to the parameter value
void S_VAL_S(char* tag, struct Options * p_opt)
{
// set variable equal to parameter value
cout << *tag << p_opt->s_param << endl;
}
// other misc. code
}
Can anyone help me figure out WHY??? the compilre is not linking these? Thanks! Joshua B. Last edited by jbarker28 : May 12th, 2003 at 02:13 PM. |
|
#2
|
||||
|
||||
|
It sounds like your project file doesn't have proj_lib.cpp included in the project. Merely #including proj_lib.h does NOT include proj_lib.cpp into your project. What you need to do is go to Project-->Add To Project-->Files and add proj_lib.cpp to your project. Hope this helps
![]() |
|
#3
|
|||
|
|||
|
Man, I feel like smacking my forhead over here...
I turns out my function prototype and my function definition were not the same... void S_VAL_I(char* tag, struct Options * p_opt); // function prototype void S_VAL_I(char tag, struct Options * p_opt) // function definition { // ... } all this headache over a pointer discrepency... lol... I feel so dirty Thanks anyways... Joshua B. |
![]() |
| Viewing: Dev Shed Forums > Programming Languages > C Programming > error LNK2001 when compiling under VS 6.0 |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|