I am trying to use this code for the Porter stemming algorithm in a C++ program I've already written. I followed the instructions near the end of the file for using the code as a separate module. I created a file, stem.c, that ends after the definition and has
extern int stem(char * p, int i, int j) ...
It worked fine in Xcode but it does not work for me on Unix with gcc 4.1.1--strange because usually I have no problem moving between the two. I get the error
ld: fatal: symbol `stem(char*, int, int)' is multiply-defined: (file /var/tmp//ccrWWlnb.o type=FUNC; file /var/tmp//cc6rUXka.o type=FUNC); ld: fatal: File processing errors. No output written to cluster
I've looked online and it seems like there are many things I could have wrong, but I'm not sure what combination of a header file, extern "C", etc. would work.
That error means that the symbol (stem) is defined in more than one module.
You can declare the symbol in as many modules as you want. A declaration of a function looks like this:
int stem(char * p, int i, int j);
You don't need the "extern" keyword, although it doesn't hurt anything. For functions declarations, it's implied.
A definition of a function looks like this:
int stem(char * p, int i, int j)
{
/* body of your function */
}
The "multiply-defined" error indicates that you have two modules with a definition for the same function. That usually means that you have two files that define the function, or two files that #include a file that defines the function. Normally, you should not put function definitions in files that you #include. Put the definition in a .c, .cpp, or .cc file and just put a declaration in a .h file that you #include.
For example, you could create a stem.h file with this in it:
int stem(char * p, int i, int j);
Then, #include "stem.h"
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With