Author Topic: Compiling with libpq-fe.h  (Read 377 times)

Offline gcclinux

  • Single posting newcomer
  • *
  • Posts: 1
Compiling with libpq-fe.h
« on: September 22, 2020, 06:08:28 pm »
Hello,

I have now tried adding in link tab, directory search and everything I can think off but I can not get it to work in CodeBlocks...

Command line works:

$ gcc -o server_version server_version.c -I/usr/include/postgresql -L/usr/lib/postgresql/12/lib/ -lpq -std=c99

Error from Build Log in CodeBlocks :

-------------- Build: Release in postgresql (compiler: GNU GCC Compiler)---------------

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>
                      ^
compilation terminated.
Process terminated with status 1 (0 minute(s), 0 second(s))
1 error(s), 0 warning(s) (0 minute(s), 0 second(s))



Please can someone assist as I am trying postgresql for the first time and codeblocks is not helping me :-)

Offline BlueHazzard

  • Developer
  • Lives here!
  • *****
  • Posts: 2847
Re: Compiling with libpq-fe.h
« Reply #1 on: September 23, 2020, 09:29:37 am »
Code: [Select]
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?

Offline Miguel Gimenez

  • Lives here!
  • ****
  • Posts: 569
Re: Compiling with libpq-fe.h
« Reply #2 on: September 23, 2020, 10:27:33 am »
Have you tested #include "libpq-fe.h" (with double quotes, not angle brackets)?

Also, in the command line that works you have
Code: [Select]
-L/usr/lib/postgresql/12/lib/but in the generated one you have
Code: [Select]
-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.