Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Docker php:7.4-fpm-alpine pecl install and build from source fails #31

Open
Anecho opened this issue Sep 21, 2022 · 13 comments
Open

Docker php:7.4-fpm-alpine pecl install and build from source fails #31

Anecho opened this issue Sep 21, 2022 · 13 comments

Comments

@Anecho
Copy link

Anecho commented Sep 21, 2022

Versions according to https://pkgs.alpinelinux.org/packages

.Dockerfile for pecl install tensor

FROM php:7.4-fpm-alpine

RUN apk update && apk --no-cache add --update \
    # Optional To Compile Extension
    # A C compiler v12.1.1_git20220630-r5
    autoconf gcc musl-dev g++ \
    # A Fortran compiler v12.1.1_git20220630-r5
    bash bash-doc bash-completion musl-dev gfortran gdb make \
    # OpenBLAS development package v0.3.21-r0
    openblas-dev \
    # LAPACKE C interface to LAPACK v3.10.1-r0
    lapack \
    # re2c v3.0-r0
    re2c \
    # make v4.3-r0
    make \
    # autoconf v2.71-r0
    autoconf \
    # automake v1.16.5-r1
    automake \
    # build-essentials for Alpine 
    alpine-sdk build-base
    # execinfo.h missing error: 
    # libexecinfo-dev

RUN pecl install tensor

Error from pecl install tensor:

#0 10.20 /tmp/pear/temp/tensor/ext/kernel/backtrace.c:15:10: fatal error: execinfo.h: No such file or directory
#0 10.20    15 | #include <execinfo.h>
#0 10.20       |          ^~~~~~~~~~~~
#0 10.20 compilation terminated.
#0 10.20 make: *** [Makefile:202: kernel/backtrace.lo] Error 1
#0 10.20 ERROR: `make' failed

Fixed by apk add libexecinfo-dev awslabs/aws-lambda-cpp#124 (comment)

But then other error pops up:

#0 85.60 /usr/lib/gcc/x86_64-alpine-linux-musl/11.2.1/../../../../x86_64-alpine-linux-musl/bin/ld: cannot find -llapacke: No such file or directory
#0 85.61 collect2: error: ld returned 1 exit status
#0 85.61 make: *** [Makefile:289: tensor.la] Error 1
#0 85.62 ERROR: `make' failed

musl/bin/ld file is there.

bash-5.1# ls /usr/lib/gcc/x86_64-alpine-linux-musl/11.2.1/../../../../x86_64-alpine-linux-musl/bin/ -l
total 4936
-rwxr-xr-x    2 root     root         59536 Jul  7 13:57 ar
-rwxr-xr-x    2 root     root        659448 Jul  7 13:57 as
-rwxr-xr-x    4 root     root       1469904 Jul  7 13:57 ld
-rwxr-xr-x    4 root     root       1469904 Jul  7 13:57 ld.bfd
-rwxr-xr-x    2 root     root         52392 Jul  7 13:57 nm
-rwxr-xr-x    2 root     root        157808 Jul  7 13:57 objcopy
-rwxr-xr-x    2 root     root        332720 Jul  7 13:57 objdump
-rwxr-xr-x    2 root     root         59568 Jul  7 13:57 ranlib
-rwxr-xr-x    2 root     root        620928 Jul  7 13:57 readelf
-rwxr-xr-x    2 root     root        157808 Jul  7 13:57 strip

Also tried building from source - same error on make step pops up.

.Dockerfile for build tensor from source

RUN apk update && apk --no-cache add --update \
    # A C compiler v12.1.1_git20220630-r5
    autoconf gcc musl-dev g++ cmake \
    # A Fortran compiler v12.1.1_git20220630-r5
    bash bash-doc bash-completion musl-dev gfortran gdb make \
    # OpenBLAS development package v0.3.21-r0
    openblas-dev \
    # LAPACKE C interface to LAPACK v3.10.1-r0
    lapack \
    # re2c v3.0-r0
    re2c \
    # make v4.3-r0
    make \
    # autoconf v2.71-r0
    autoconf \
    # automake v1.16.5-r1
    automake \
    # build-essentials for Alpine 
    alpine-sdk build-base \
    # execinfo.h missing: https://github.com/awslabs/aws-lambda-cpp/issues/124#issuecomment-968302646
    libexecinfo-dev

# RUN pecl install tensor

RUN git clone https://github.com/RubixML/Tensor Tensor

WORKDIR /var/www/html/Tensor/ext

RUN phpize \
    && ./configure \
    && make \
    && make install

Error from build tensor from source:

#0 86.23 /usr/lib/gcc/x86_64-alpine-linux-musl/11.2.1/../../../../x86_64-alpine-linux-musl/bin/ld: cannot find -llapacke: No such file or directory
#0 86.27 collect2: error: ld returned 1 exit status
#0 86.28 make: *** [Makefile:289: tensor.la] Error 1

What am I missing here?

@adrolter
Copy link

Is there a known solution to this? I'm running into the same problem with PHP 8.1.10 on Alpine 3.16. I also have lapack-dev installed.

@adrolter
Copy link

@Kabingeran Why would anyone message you privately to discuss this topic? Just post your solution here if you have one

@Kabingeran
Copy link

@adrianguenter In each case, it will probably be different. Why write to me in private? To get your solution. Well, try making symbolic links. This should help.

@epoxa
Copy link

epoxa commented Apr 10, 2023

@adrianguenter In each case, it will probably be different. Why write to me in private? To get your solution. Well, try making symbolic links. This should help.

What symbolic links do you mean? I have exactly the same issue when trying to build the extension from source.

@adrolter
Copy link

@epoxa Yeah, I don't know why they're being so cryptic. There's definitely a general purpose solution to this, so if they've solved it I wish they'd just share it with the community.

@Kabingeran
Copy link

Kabingeran commented Apr 11, 2023

There is no universal solution. Try installing lapack with the specified version and making symlinks if needed. There are several deprecation errors after installing on 8.1. No need to install on 8.1 yet.

@adrolter
Copy link

Most things can be generalized to a certain degree, though, and I'm sure that is the case here as well. You're being intentionally cryptic for some strange reason.

@mlocati
Copy link
Contributor

mlocati commented Sep 13, 2023

You need to know the Alpine version you are using (cat /etc/os-release):

  • For Alpine versions older than 3.11 I don't have a solution
  • For Alpilne 3.11 to 3.14, you need the lapack, lapack-dev, openblas-dev apk packages
  • For Alpine 3.15 to 3.17, you need the lapack, lapack-dev, openblas-dev apk packages and you need to run
    ln -s /usr/lib/liblapacke.so.3 /usr/lib/liblapacke.so
  • For Alpine 3.18 and newer, you need the liblapack, lapack-dev, openblas-dev apk packages

@mlocati
Copy link
Contributor

mlocati commented Sep 13, 2023

PS: if and once #39 will be merged, and a new version is published on PECL, I can update my install-php-extensions script so that you can install tensor very easily.

@Kabingeran
Copy link

Kabingeran commented Oct 14, 2023

It seems PECL has been updated. For Alpine in Docker this worked for me:

RUN apk add --no-cache openblas-dev libexecinfo-dev lapack=3.10.1-r0
RUN ln -s /usr/lib/liblapack.so.3 /usr/lib/liblapack.so \
&& ln -s /usr/lib/liblapacke.so.3 /usr/lib/liblapacke.so
RUN pecl install tensor
RUN docker-php-ext-enable tensor

@mlocati
Copy link
Contributor

mlocati commented Oct 14, 2023

Yep, that works.
You an also check here to see what should be done in order to have the correct apk (and apt) dependencies:

https://github.com/RubixML/Tensor/blob/master/.github/workflows/ci-ext.yml#L40

@mlocati
Copy link
Contributor

mlocati commented Oct 14, 2023

@Kabingeran you can also use this script of mine to install tensor (and a ton of other PHP extensions) without having to worry about the system requirements (apk/apt libraries, symbolic links, and so on).
Simply write

install-php-extensions tensor

and you are done.

@Kabingeran
Copy link

Kabingeran commented Oct 14, 2023

I tried it on Alpine 3.16. It is unlikely that anyone will need older versions.
Alpine 3.19:
RUN apk add --no-cache openblas-dev lapack-dev
RUN pecl install tensor
RUN docker-php-ext-enable tensor

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants