0

I have been working on the load function for pset5 for more than 2 weeks and I am keep receiving clang error: linker command failed with exit code 1. Bellow I have the code so everyone can take a look at it and the error message. Can someone please give me a guidance on where the problem seems to be hidden? Thank you

bool load(const char* dictionary) {

node *head=NULL;
FILE *fp=fopen(dictionary, "r");

if (fp==NULL)
{
    fprintf(fp,"File dictionary could not be opened.\n");
    return false; 
}

while (!feof(fp))
{
    node *new_node=malloc(sizeof(node));
    fscanf(fp, "%s", new_node->word);
    int h=hash_function(new_node->word, strlen(new_node->word));

    if (hash_table[h]==NULL)
    {
        hash_table[h]=new_node;
        head=hash_table[h];
        head->next=NULL;
    }
    else if (hash_table[h]!=NULL)
    {
        new_node->next=head->next;
        head->next=new_node;
    }
}

if(feof(fp))
{
    return true;
    fclose(fp); 
}

return false;
fclose(fp);

}

Compiling /home/ubuntu/workspace/pset5/dictionary.c ... clang dictionary.o -lcs50 -lm -o dictionary

/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 0 has invalid symbol index 11

/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 1 has invalid symbol index 12

/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 2 has invalid symbol index 2

/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 3 has invalid symbol index 2

/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 4 has invalid symbol index 11

/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 5 has invalid symbol index 13

/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 6 has invalid symbol index 13

/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 7 has invalid symbol index 13

/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 8 has invalid symbol index 12

/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 9 has invalid symbol index 13

/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 10 has invalid symbol index 13

/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 11 has invalid symbol index 13

/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 12 has invalid symbol index 13

/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 13 has invalid symbol index 13

/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 14 has invalid symbol index 13

/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 15 has invalid symbol index 13

/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 16 has invalid symbol index 13

/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 17 has invalid symbol index 13

/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 18 has invalid symbol index 13

/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 19 has invalid symbol index 21

/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_line): relocation 0 has invalid symbol index 2

/usr/bin/../lib/gcc/x86_64-linux-gnu/4.8/../../../x86_64-linux-gnu/crt1.o: In function _start': (.text+0x20): undefined reference tomain'

clang: error: linker command failed with exit code 1 (use -v to see invocation) make: *** [dictionary] Error 1 Please be sure to stop other debuggers before continuing.

Process exited with code: 0

6
  • would be great if you updated your question with the full error message as well as the command that produced the error!
    – kzidane
    Commented Jan 19, 2016 at 4:33
  • Thank you Kareem. I just updated the question. I can't identify a particular code line that generates the error.
    – dean.d
    Commented Jan 19, 2016 at 4:45
  • are you trying to make dictionary?
    – kzidane
    Commented Jan 19, 2016 at 4:46
  • Yes. I am trying to compile dictionary.c
    – dean.d
    Commented Jan 19, 2016 at 12:58
  • yeah, you should make speller!
    – kzidane
    Commented Jan 19, 2016 at 13:00

1 Answer 1

0

You are trying to write to a NULL file pointer

if (fp==NULL) { fprintf(fp,"File dictionary could not be opened.\n"); return false; }

Change fprintf function to a printf function then it should work

3
  • Thank you! I changed the fprintf and it seems we are good now!
    – dean.d
    Commented Jan 20, 2016 at 20:49
  • That's great, don't wait as long next time to ask a question. Nothing worse than getting stuck on something like that.
    – Shauny
    Commented Jan 20, 2016 at 21:13
  • I know you are right. In the past i was able to find an answer through other peoples questions but this time i was totally lost! Thanks again for your help!
    – dean.d
    Commented Jan 20, 2016 at 21:42

You must log in to answer this question.

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