Shiwangini
Shiwangini

Reputation: 836

example.c:1:22: fatal error: postgres.h: No such file or directory

I'm trying to create my own function (using C) in postgres for which I'm referring this doc: http://www.linuxgazette.cz/139/peterson.html

For compiling - I'm referring: Section 33.9.6 . But, when I run below command:

   cc -fpic -c example.c

I get this error:

   example.c:1:22: fatal error: postgres.h: No such file or directory
 #include "postgres.h"
                  ^
compilation terminated.

I have also installed postgresql-server-dev-all package and tried with the solution provided in this link: How to fix 'postgres.h' file not found problem?

Nothing working for me. Please let me know how I can have postgres.h file. I'm using postgres-12 on centos -7.

Upvotes: 0

Views: 5493

Answers (2)

Nikolay Pelipets
Nikolay Pelipets

Reputation: 21

for ubuntu: apt-get -y install postgresql-server-dev-13 after apt-get -y install postgresql-13.

Or more generally:

apt-get -y install postgresql-xx
apt-get -y install postgresql-server-dev-xx

where xx is the target PostgreSQL version.

Upvotes: 2

Laurenz Albe
Laurenz Albe

Reputation: 246308

First: If you didn't install PostgreSQL from source, make sure that you installed the headers, which are in the -devel package.

If the problem persists even with the headers installed, the reason is that you forgot to tell the compiler where to look for header files:

cc -fpic -I /location/of/postgres/include -c example.c

To find that location, you can use pg_config:

pg_config --includedir

There is a similar --libdir option to show the library path for when you link the executable.

Upvotes: 1

Related Questions