Installing pgvector on MacOS

Following the normal instructions you might get an error like this:

gcc -Wall -Wmissing-prototypes -Wpointer-arith -Wdeclaration-after-statement -Werror=vla -Werror=unguarded-availability-new -Wendif-labels -Wmissing-format-attribute -Wformat-security -fno-strict-aliasing -fwrapv -Wno-unused-command-line-argument -g -isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX11.sdk -mmacosx-version-min=10.15 -arch x86_64 -arch arm64 -O2  -ftree-vectorize -fassociative-math -fno-signed-zeros -fno-trapping-math  -fvisibility=hidden -I. -I./ -I/Library/PostgreSQL/16/include/postgresql/server -I/Library/PostgreSQL/16/include/postgresql/internal -I/opt/local/Current_v15/include -isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX11.3.sdk  -I/opt/local/20220418/include/libxml2 -I/opt/local/Current_v15/include -I/opt/local/Current_v15/include  -I/opt/local/Current_v15/include/libxml2 -I/opt/local/Current_v15/include -I/opt/local/Current_v15/include/openssl/  -c -o src/bitutils.o src/bitutils.c
clang: warning: no such sysroot directory: '/Library/Developer/CommandLineTools/SDKs/MacOSX11.3.sdk' [-Wmissing-sysroot]
clang: warning: no such sysroot directory: '/Library/Developer/CommandLineTools/SDKs/MacOSX11.3.sdk' [-Wmissing-sysroot]
In file included from src/bitutils.c:1:
In file included from /Library/PostgreSQL/16/include/postgresql/server/postgres.h:45:
/Library/PostgreSQL/16/include/postgresql/server/c.h:59:10: fatal error: 'stdio.h' file not found
   59 | #include <stdio.h>
      |          ^~~~~~~~~
1 error generated.
make: *** [src/bitutils.o] Error 1

The installation notes will tell you to reinstall the xcode command line tools, but this won't work. The problem is you're missing the MacOSX11.3.sdk. This is an old SDK. It's actually a problem with Postgres itself, rather than pgvecor. You can read about it in the issue here

The solution is download the old SDK from this repository and copy / link it into the older where gcc is looking for it:

git clone git@github.com:phracker/MacOSX-SDKs.git && cd MacOSX-SDKs
sudo ln -s /absolute/path/MacOSX-SDKs/MacOSX11.3.sdk /Library/Developer/CommandLineTools/SDKs/MacOSX11.3.sdk

Then go back to where you downloaded pgvector and try make again. Everything should work!