Jasper Zhou
Jasper Zhou

Reputation: 527

How to fix 'postgres.h' file not found problem?

I am trying to write a base type for PostgreSQL in C (using xcode), and I already installed PostgreSQL 11, but it seems that postgres.h cannot be simply included in the file ("'postgres.h' file not found").

Could someone tell me how to fix that problem? And can I write code under an arbitary directory, or do I have to write under the PostgreSQL directory?

Or perhaps the question should be: how to install header files like postgres.h?

Upvotes: 30

Views: 47029

Answers (3)

Nuzhat Ansari
Nuzhat Ansari

Reputation: 821

Install postgresql-server-dev package with this command:

sudo apt install postgresql-server-dev-XX

Replace [XX] with your already installed version of PostgreSQL: 9.5, 10, 11, 12, 13, 14, 15

Upvotes: 81

Usman Ali Syed
Usman Ali Syed

Reputation: 39

I was facing the same issue while compiling postgis 3.1.7 for postgresql@13 on my Mac. The problem was that in pg_config the link to server file was

/opt/homebrew/opt/postgresql@13/include/server

While the actual server folder was in

/opt/homebrew/opt/postgresql@13/include/postgresql/server

So I moved the entire "server" folder up a directory inside "/include". And viola, postgis compiled and installed perfectly.

Upvotes: 3

Luis Colorado
Luis Colorado

Reputation: 12668

You have several approaches here:

  • Search for the file yourself, using some command like

    find / -name "postgres.h" -print
    

    this will tell you (on my Mac does) the file is in:

    /usr/local/Cellar/postgresql/11.2_1/include/server/postgres.h
    

    and add the -I /usr/local/Cellar/postgresql/11.2_1/include/server option to the compiler. Check your postgresql version for the possibility of having a different one.

  • Probably there's another package for database development. Search for a package named postgresql-dev or similar, and install it. After searching packages with:

     brew search postgres 
    

    and

     brew search psql
    

    on my system doesn't appear anything that matches.

EDIT

I've checked a FreeBSD system for that file and it appears on

/usr/local/include/postgresql/server/postgres.h

So probably you have to #include <server/postgres.h> instead, and use the appropiate -I flag (as mentioned above)

Upvotes: 4

Related Questions