0

Compiling in Ubuntu 20.04.4 LTS, g++ returns

libpq-fe.h is not found

The system already has it installed (sudo apt-get install libpq-dev) in

/usr/include/postgresql/libpq-fe.h

I tried to set the compilation path with option -I/usr/include/postgresql but it still claims about missing libpq-fe.h

alboforlizo
  • 170
  • 1
  • 6

1 Answers1

1

As you can see, I had to manually insert both -I/usr/include/postgresql and -L/usr/lib/x86_64-linux-gnu to make -lpq (libpq) work with g++ in Ubuntu:

TARGET = prog
LIBS = -lm -lcrypto -lpq -lpthread
CC = g++
CFLAGS = -g -Wall
ODIR = ../src

.PHONY: default all clean

default: $(TARGET)
all: default

OBJS = $(patsubst %.cpp, %.o, $(wildcard ../src/*.cpp))
HEADERS = $(wildcard ../src/*.h)

all: $(TARGET)
$(TARGET): $(OBJS)
        $(CC) -L/usr/lib/x86_64-linux-gnu -o $@ $^ $(LIBS)
$(ODIR)/%.o: $(ODIR)/%.cpp
        $(CC) $(CFLAGS) -I/usr/include/postgresql -c $< -o $@

clean:
        -rm -f ../src/*.o
        -rm -f $(TARGET)

In case of "cannot find -lpq" with libpq.so.5 already in /usr/lib/x86_64-linux-gnu:

sudo ln -s /usr/lib/x86_64-linux-gnu/libpq.so.5 /usr/lib/x86_64-linux-gnu/libpq.so
alboforlizo
  • 170
  • 1
  • 6