pgRouting / osm2pgrouting

Import tool for OpenStreetMap data to pgRouting database
https://pgrouting.org
GNU General Public License v2.0
291 stars 111 forks source link

Problem compiling on alpine linux (libpqxx) #303

Closed iboates closed 7 months ago

iboates commented 7 months ago

Problem

I cannot compile on Alpine Linux due to libpqxx not being found

To Reproduce

Compile on Alpine Linux. I am doing so in a Dockerfile (pretty typical for Alpine):

FROM docker.io/alpine:latest

RUN apk add --no-cache \
    git \
    expat \
    expat-dev \
    boost-dev \
    boost-program_options \
    postgresql-dev \
    cmake \
    make \
    g++ \
    libpq-dev

RUN git clone -b v2.3.8 https://github.com/pgRouting/osm2pgrouting.git
WORKDIR osm2pgrouting

RUN cmake -H. -Bbuild

The compilation error is:

 > [5/5] RUN cmake -DSKIP_PQXX_STATIC=OFF -DSKIP_PQXX_SHARED=ON -H. -Bbuild:                                         
0.366 CMake Deprecation Warning at CMakeLists.txt:1 (cmake_minimum_required):                                        
0.366   Compatibility with CMake < 3.5 will be removed from a future version of                                      
0.366   CMake.                                                                                                       
0.366                                                                                                                
0.366   Update the VERSION argument <min> value or use a ...<max> suffix to tell
0.366   CMake that the project does not need compatibility with older versions.
0.366 
0.366 
0.438 -- The C compiler identification is GNU 13.2.1
0.506 -- The CXX compiler identification is GNU 13.2.1
0.529 -- Detecting C compiler ABI info
0.625 -- Detecting C compiler ABI info - done
0.643 -- Check for working C compiler: /usr/bin/cc - skipped
0.644 -- Detecting C compile features
0.645 -- Detecting C compile features - done
0.659 -- Detecting CXX compiler ABI info
0.758 -- Detecting CXX compiler ABI info - done
0.777 -- Check for working CXX compiler: /usr/bin/c++ - skipped
0.778 -- Detecting CXX compile features
0.779 -- Detecting CXX compile features - done
0.781 -- POSTGRESQL_PG_CONFIG is /usr/bin/pg_config
0.786 -- POSTGRESQL_INCLUDE_DIR: /usr/include/postgresql
0.786 -- POSTGRESQL_LIBRARIES: /usr/lib/libpq.so
0.794 CMake Error at /usr/share/cmake/Modules/FindPackageHandleStandardArgs.cmake:230 (message):
0.794   libpqxx couldn't be found (missing: PQXX_LIBRARIES PQXX_INCLUDE_DIR)
0.794 Call Stack (most recent call first):
0.794   /usr/share/cmake/Modules/FindPackageHandleStandardArgs.cmake:600 (_FPHSA_FAILURE_MESSAGE)
0.794   cmake/FindPQXX.cmake:58 (FIND_PACKAGE_HANDLE_STANDARD_ARGS)
0.794   CMakeLists.txt:15 (find_package)
0.794 
0.794 
0.794 -- Configuring incomplete, errors occurred!

TL;DR:

0.794 CMake Error at /usr/share/cmake/Modules/FindPackageHandleStandardArgs.cmake:230 (message):
0.794   libpqxx couldn't be found (missing: PQXX_LIBRARIES PQXX_INCLUDE_DIR)

It's worth noting that on Alpine, the package is called libpq-dev, not libpqxx-dev. (link) I'm not that experienced in C++ but I guess that there are missing headers? Any ideas on what I can try? Ive already tried a lot of monkey-pasting from other related issues to no avail.

Expectation

Should be able to compile

iboates commented 7 months ago

In the end I realized that the problem is actually quite simple, and it is that libpq is not the same thing as libpqxx. Furthermore, libpqxx is just not available on alpine linux, and must be compiled from source. Therefore, the below Dockerfile works. If you are not using docker, you can quite easily extract the commands from it to compile on Alpine, if for whatever bizarre reason, you are choosing to torment yourself by using Alpine for anything other than Docker.

FROM docker.io/alpine:latest

RUN apk add --no-cache \
    git \
    expat \
    expat-dev \
    boost-dev \
    boost-program_options \
    postgresql-dev \
    cmake \
    make \
    g++

# libqxx is not available on apk, must build from source
RUN git clone https://github.com/jtv/libpqxx.git
WORKDIR libpqxx
RUN cmake . -DCMAKE_INSTALL_PREFIX=/usr -DSKIP_BUILD_TEST=ON
RUN make
RUN make install
WORKDIR ..

RUN git clone -b v2.3.8 https://github.com/pgRouting/osm2pgrouting.git
WORKDIR osm2pgrouting

RUN cmake -H. -Bbuild
WORKDIR build/
RUN make
RUN make install