How to Install libpq-dev on CentOS 5.5 for PostgreSQL Development


2 views

When working with PostgreSQL database connectivity in C/C++ applications on Linux, the libpq-dev package (known as libpq-devel in RHEL-based systems) is essential. While Ubuntu/Debian users can simply run apt-get install libpq-dev, CentOS 5.5 presents some unique challenges due to its age and package naming conventions.

The equivalent package in CentOS/RHEL systems is postgresql-devel, which provides:

  • Header files for libpq (C interface library)
  • Development libraries needed for compiling applications
  • Utility programs like pg_config

For CentOS 5.5, try these approaches:

# Standard repository method
yum install postgresql-devel

# If you need a specific PostgreSQL version
yum install postgresql92-devel  # For PostgreSQL 9.2

After installation, verify the headers are available:

# Check for libpq-fe.h
ls /usr/include/libpq-fe.h

# Verify pg_config
pg_config --includedir

If you encounter missing dependencies, consider:

# Clean the yum cache
yum clean all

# Install base PostgreSQL packages first
yum install postgresql postgresql-libs

Here's a simple test program to verify your development environment:

#include <stdio.h>
#include <libpq-fe.h>

int main() {
    printf("PostgreSQL client version: %d\n", PQlibVersion());
    return 0;
}

Compile with:

gcc test_pq.c -o test_pq -I/usr/include/postgresql -lpq

If the standard packages aren't available:

  • Compile from source using PostgreSQL's official packages
  • Consider using a newer CentOS release or container
  • Use third-party repositories like RPMForge (with caution)

When working with PostgreSQL development, the library naming conventions differ between Ubuntu/Debian and CentOS/RHEL systems. What's called libpq-dev in Ubuntu is part of the postgresql-devel package in CentOS.

For CentOS 5.5, you'll need to run:

yum install postgresql-devel

This package provides all necessary files including:

  • libpq-fe.h (header file)
  • libpq.so (shared library)
  • pg_config (utility)

After installation, verify the files are in place:

ls /usr/include/libpq-fe.h
ls /usr/lib/libpq.so*
pg_config --includedir
pg_config --libdir

Here's a simple C program to test your PostgreSQL development environment:

#include <stdio.h>
#include <libpq-fe.h>

int main() {
    int lib_ver = PQlibVersion();
    printf("PostgreSQL client version: %d\n", lib_ver);
    return 0;
}

Compile with:

gcc -I/usr/include/postgresql -lpq test_pq.c -o test_pq

If the package isn't found, you may need to enable the CentOS 5.5 repositories which have been archived:

wget -O /etc/yum.repos.d/CentOS-Base.repo \
https://vault.centos.org/5.5/CentOS-Base.repo
yum clean all
yum makecache

If yum installation fails, consider these alternatives:

  1. Building from source:
    wget https://ftp.postgresql.org/pub/source/v8.4.22/postgresql-8.4.22.tar.gz
    tar xzf postgresql-8.4.22.tar.gz
    cd postgresql-8.4.22
    ./configure
    make -C src/interfaces/libpq
    make -C src/bin/pg_config
  2. Using RPM packages directly

If you encounter version conflicts or missing dependencies:

yum provides */libpq-fe.h
yum install compat-postgresql-libs

Remember that CentOS 5.5 reached end-of-life in 2014, so consider upgrading if possible for security updates.