Error “ld: symbol not found for architecture x86_64”

This error indicate that your code, usually from C family language, has imported a header but has not yet been linked to it?s implementation.

For example there is a header SimpleMath.h

// SimpleMath.hint divide_by_zero(int i);

Then we import it in main.c

// main.c#include “SimpleMath.h”int main() { int result = divide_by_zero(100); printf(“Result is %d”, result);}

When we compile it without implementation of SimpleMath.h then we we?ll get ld: symbol not … (bla-bla-bla)

The solution is to compile it with SimpleMath.c

clang main.c SimpleMath.c -o program

Or to link it with system implementation if there any.

clang main.c -LSimpleMath -o program

Fixed? Not yet. You?ll want to read more about C language then.

Oh yes, our SimpleMath.c implementation is

// SimpleMath.c#include “SimpleMath.h”int divide_by_zero(int i) { exit(1);}

Happy fixing error!

1

No Responses

Write a response