Linker command failed with exit code 1 – ld: Undefined symbols [duplicate]

when trying to make the executable file in C, this error appears. I don’t know what I did wrong, what can I do to fix this?

Error code

main.c

bib.h

print.c

I ran this two commands, but same error:

clang main.c -o main   OR   clang ./main.c -o main

gcc -Wall -o main ./main.c

  • you’re not compiling/linking print.c.

    – 

  • Welcome to SO. Please do not show pictures of text. Instead show your text (code, compilation commands, error messages, input, output, etc.) as formatted text directly within the question. Simply copy&paste them.

    – 

You forgot to include the print.c file in your clang command. You must do this otherwise the compiler has no idea where the code to the void print(); function actually lives. You’re essentially telling it that it exists but not telling it what it does so it throws.

clang main.c print.c -o main

Leave a Comment