Cのstatic逆だった #おっさんのダメ記憶
$ cat main.c
#include <stdio.h>
extern char *name;
int
main(void)
{
printf("Hello, %s!\n", name);
return 0;
}
$ cat name.c
char *name = "world";
$ gcc main.c name.c && ./a.out
Hello, world!
staticをつけると
$ cat name.c
static char *name = "world";
$ gcc main.c name.c && ./a.out
Undefined symbols for architecture x86_64:
"_name", referenced from:
_main in main-653948.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)