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.