Undefined symbols for architecture x86_64: "_main", referenced from: implicit entry/start for main executable

Viewed 514
#include <unistd.h>
void    ft_print_alphabet(void)
{
    write(1, 
 "abcdefghijklmnopqrstuvwxyz", 26);
}

I tried running the above in VS Code and I got the following error:

Undefined symbols for architecture x86_64:

"_main", referenced from:

implicit entry/start for main executable

ld: symbol(s) not found for architecture x86_64

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

1 Answers

You need to have a main function as C expects one, and then you can call your function from main():

#include <unistd.h>

void ft_print_alphabet(void)
{
    write(1, 
 "abcdefghijklmnopqrstuvwxyz", 26);
}

int main() {
    ft_print_alphabet();
    return 0;
}
Related