I am trying to compile a C program that uses libpq library in a Docker container. Here’s my Dockerfile:
FROM ubuntu:latest
RUN apt-get update &&
apt-get install -y build-essential libpq-dev
WORKDIR /app
# Copy the source files into the container's working directory
COPY tmp.c .
# Compile the source file directly in the Dockerfile
RUN gcc -Wall -Wextra -pedantic -g -o my_program tmp.c -lpq
CMD ["./my_program"]
When I try to build the Docker image using docker build . -t my_image, I get the following error:
tmp.c:4:10: fatal error: libpq-fe.h: No such file or directory
#include "libpq-fe.h"
^~~~~~~~~~~~
compilation terminated.
I have tried installing libpq-dev package, but it doesn’t seem to solve the issue. What am I missing here? How can I compile my program with libpq in the Docker container?
As a next step, I also want to test for memory leaks using Valgrind. Can you please advise me on how to do this after compiling the code?
I am using Mac for the purpose of analyzing the leakage, I have used leak but it wasn’t that much useful.
2
Answers
I have some suggestions may help:
I could able to have that running on my machine through adding
–I/usr/include/postgresql in the gcc command
I suggest you try to reinstall the libpq-dev package.
If it doesn’t work, another solution could be to use an alternative to Docker, like wsl.