gcc -Wall -I/usr/include/postgresql -I/usr/lib/postgresql/12/lib/ -c /home/ricardo/Programming/c/postgresql/server_version.c -o obj/Release/server_version.o
g++ -o bin/Release/postgresql obj/Release/server_version.o
/home/ricardo/Programming/c/postgresql/server_version.c:3:22: fatal error: libpq-fe.h: No such file or directory
#include <libpq-fe.h>
Why is there a g++ ?
Are you mixing cpp and c files?
Are you using a project?
Have you tested #include "libpq-fe.h" (with double quotes, not angle brackets)?
Also, in the command line that works you have
-L/usr/lib/postgresql/12/lib/
but in the generated one you have
-I/usr/lib/postgresql/12/lib/
This is because you put /usr/lib/postgresql/12/lib in the compiler search path, but it must go in the linker search path.