Symbol referencing error
Andrea 'Fyre Wyzard' Bocci
fwyzard@inwind.it
Wed Feb 6 15:28:00 GMT 2002
At 15.24 06/02/2002 (GMT +0000), kabir.patel@uk.andersen.com wrote:
>I have the following in my code:
>
>char *pToUpperC()
>
>and also...
>
>fprintf(stream,",%s", pToUpperC(pNote));
It seems strange to be a GCC related problem.
Are those in the same file (with the funcion before the fprintf) ?
If not, you should use them like this:
***** Solution A) All in one file:
************************************************
// main.c
char *pToUpperC(char *argument) { // this defines the function
...
}
...
fprintf(stream,",%s", pToUpperC(pNote)); // this uses it
// end of main.c
***** Solution B) All in one file, with forward declaration
************************************************
// main.c
char *pToUpperC(char *argument); // this declares the function
...
fprintf(stream,",%s", pToUpperC(pNote)); // this uses it
...
char *pToUpperC(char *argument) { // this defines it
...
}
// end of main.c
***** Solution C) Two different files
************************************************
// file pToUpper.h
#ifndef pToUpper_h
#define pToUpper_h
char *pToUpperC(char *argument); // this declares the function
#endif // pToUpper_h
// end of file pToUpper.h
// file pToUpper.c
char *pToUpperC(char *argument) { // this defines the function
...
}
// end of file pToUpper.c
// main.c (where you call pToUpper() from)
#include "pToUpper.h"
...
fprintf(stream,",%s", pToUpperC(pNote)); // this uses the function
...
// end of main.c
*****************************************************
In cases A & B, compile with
gcc main.c -o main
In case C with
gcc main.c pToUpper.c -o main
*****************************************************
If all this sound silly, I'm sorry, but I couldn't think of anything else.
fwyzard
More information about the Gcc-help
mailing list