Ld: symbol(s) not found for architecture arm64 clang: error: linker command failed with exit code 1 (use -v to see invocation)

Explanation of ld: symbol(s) not found for architecture arm64 clang: error: linker command failed with exit code 1 (use -v to see invocation)

When you encounter the “ld: symbol(s) not found for architecture arm64 clang: error: linker command failed with exit code 1” error, it typically means that the linker is unable to find certain symbols (functions, variables, etc.) during the compilation process.

This error is commonly seen in C or C++ programs when there is a mismatch between the declarations and definitions of the symbols. It usually happens when you forget to provide an implementation for a declared function or variable.

Here’s an example to illustrate the issue:

// main.c

#include <stdio.h>

// Function declaration
void sayHello();

int main() {
    sayHello(); // Function call
    return 0;
}
// hello.c

#include <stdio.h>

// Function definition
void sayHello() {
    printf("Hello, world!\n");
}

In the above code, the main.c file declares the sayHello() function, but the implementation is defined in the hello.c file. If you forget to compile and link both files together, you will encounter the “ld: symbol(s) not found” error.

To fix this error, make sure you have all necessary source files included for compilation and linking. You can compile multiple source files together using a command like this:

gcc main.c hello.c -o program

Once compiled successfully, the resulting executable file (program in this case) will no longer throw the “ld: symbol(s) not found” error.

Read more interesting post

Leave a comment