This is a case of it mattering where the "-l" option is specified (and it's not -raspi or arm64 specific; you can reproduce the error on a PC too):
$ gcc -O2 $(pkg-config --cflags --libs sdl2) program.c -o program && echo $?
/usr/bin/ld: /tmp/cciGcVIh.o: in function `main':
program.c:(.text.startup+0xa): undefined reference to `SDL_Init'
collect2: error: ld returned 1 exit status
Why gold is less fussy than bfd about the ordering when invoked from gcc, I'm not sure, but I don't think it's a bug necessarily (the gcc man page is fairly explicit that the ordering of "-l" options matters, which is what pkg-config is producing here.
This is a case of it mattering where the "-l" option is specified (and it's not -raspi or arm64 specific; you can reproduce the error on a PC too):
$ gcc -O2 $(pkg-config --cflags --libs sdl2) program.c -o program && echo $? c:(.text. startup+ 0xa): undefined reference to `SDL_Init'
/usr/bin/ld: /tmp/cciGcVIh.o: in function `main':
program.
collect2: error: ld returned 1 exit status
$ gcc -O2 program.c -o program $(pkg-config --cflags --libs sdl2) && echo $?
0
Why gold is less fussy than bfd about the ordering when invoked from gcc, I'm not sure, but I don't think it's a bug necessarily (the gcc man page is fairly explicit that the ordering of "-l" options matters, which is what pkg-config is producing here.