0

I typed make speller and clang produces the output below. I'm really not sure how to resolve this. I thought that it might be saying that I defined the hash function twice but I don't think I have. Any help would be much appreciated!!

clang -ggdb3 -O0 -Qunused-arguments -std=c11 -Wall -Werror   -c -o speller.o speller.c
clang -ggdb3 -O0 -Qunused-arguments -std=c11 -Wall -Werror   -c -o dictionary.o dictionary.c
clang -ggdb3 -O0 -Qunused-arguments -std=c11 -Wall -Werror -o speller speller.o dictionary.o 
dictionary.o: In function `hash_function':
/home/ubuntu/workspace/pset5/speller/./dictionary.h:34: multiple definition of `hash_function'
speller.o:/home/ubuntu/workspace/pset5/speller/./dictionary.h:34: first defined here
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [speller] Error 1

this is the hash function

int hash_function(char* key) 
{
    int hash = toupper(key[0]) - 'A'; 
    return hash % SIZE; 
}

2 Answers 2

1

True, the function is defined once in dictionary.h. However, the compiler sees that definition twice, the first time when it encounters #include "dictionary.h" in speller (notice the reference to speller.o on the second error line), and the second time when it encounters the same include in dictionary. You should define hash_function in dictionary.c instead.

0

I have a solution for this problem.enter image description here Me too have struggled a lot for the solution of this error. This error is the linker error and its a very dummy types of error but seems a lot complicated. for the solution you have to open your dictionary.c and remove #include "speller.c" .

This type of error occurs due to the linking of different files ( .c @ makefile And other c file).

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .