0

When I write this code:

#include <cs50.h> 

#include <stdio.h>

int main (void)
{
    printf ("Hello, World \n");
} 

and try to compile it gives me this error:

 $ clang hello.c

/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 to `main'

clang: error: linker command failed with exit code 1 (use -v to see invocation)

~/workspace/ $  

It's my first piece of code & I don't know what's going on.

1 Answer 1

2

An easy way to format code when posting or editing a question: after code is pasted, select it and click the {} icon in the format bar.

The compiler is complaining that there is no "main" function. But the program you have posted does have a main function. One common cause of this problem is compiling before you save the program. If there is a red dot in the editor tab, the program is not saved.

reddot

You must log in to answer this question.

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