This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Symbol referencing error


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]