openh264 icon indicating copy to clipboard operation
openh264 copied to clipboard

[build] failed to cross-build to aarch64 when building docker image

Open Lxy0415 opened this issue 4 years ago • 13 comments

version

1.6.0

desc

I tried to cross compile to aarch64 when building a docker image, this is the dockerfile

FROM debian:stretch

ENV DEBIAN_FRONTEND noninteractive
ENV TZ=Asia/Shanghai

RUN dpkg --add-architecture arm64 && apt-get update

RUN apt-get update && apt-get install -y \
                            crossbuild-essential-arm64 \
                            automake \
                            libtool \
                            pkg-config \
                            apt-utils \
                            openssh-server \
                            rsync \
                            git \
                            vim \
                            wget \
                            sshpass \
                            unzip \
                            ca-certificates \
                            --no-install-recommends

RUN apt-get install -y \
        libvpx-dev:arm64 \
        libx264-dev:arm64 \
        libfreetype6-dev:arm64 \
        --no-install-recommends

COPY arm64.cmake /root/
RUN wget -c https://github.com/Kitware/CMake/releases/download/v3.10.3/cmake-3.10.3-Linux-x86_64.tar.gz && \
    tar -xzvf cmake-3.10.3-Linux-x86_64.tar.gz && \
    cp -r cmake-3.10.3-Linux-x86_64/bin/* /usr/bin/ && \
    cp -r cmake-3.10.3-Linux-x86_64/share/cmake-3.10 /usr/share/ && \
    rm -rf cmake-3.10.3-Linux-x86_64.tar.gz cmake-3.10.3-Linux-x86_64/

RUN wget https://github.com/cisco/openh264/archive/refs/tags/v1.6.0.tar.gz \
    && tar xzvf v1.6.0.tar.gz \
    && cd openh264-1.6.0 \
    #&& make \
    && make OS=linux ARCH=aarch64 CC=aarch64-linux-gnu-gcc CXX=aarch64-linux-gnu-g++ -j8 \
    && make install

RUN echo "root:123456"|chpasswd
RUN sed -i s/PermitRootLogin\ prohibit-password/PermitRootLogin\ yes/g /etc/ssh/sshd_config
RUN sed -i s/#PermitRootLogin/PermitRootLogin/g /etc/ssh/sshd_config
ENTRYPOINT service ssh restart && bash

and get error

aarch64-linux-gnu-g++ -o h264enc codec/console/enc/src/welsenc.o -L. -lencoder -lprocessing -lcommon -lconsole_common -lpthread 
sh ./codec/common/generate_version.sh ./
fatal: Not a git repository (or any of the parent directories): .git
Keeping existing codec/common/inc/version_gen.h
nasm -DUNIX64 -f elf64 -I./codec/common/x86/   -o codec/encoder/core/x86/coeff.o codec/encoder/core/x86/coeff.asm
make: nasm: Command not found
make: *** [codec/encoder/core/x86/coeff.o] Error 127
codec/encoder/targets.mk:88: recipe for target 'codec/encoder/core/x86/coeff.o' failed
The command '/bin/sh -c wget https://github.com/cisco/openh264/archive/refs/tags/v1.6.0.tar.gz     && tar xzvf v1.6.0.tar.gz     && cd openh264-1.6.0     && make OS=linux ARCH=aarch64 CC=aarch64-linux-gnu-gcc CXX=aarch64-linux-gnu-g++ -j8     && make install' returned a non-zero code: 2

Buf if i skip the openh264 build process in the image building phase, i manager to build it in the container without error. How should I deal with this error? I hope I can cross compile openh264 in the mirror building phase.

Lxy0415 avatar Jun 30 '21 08:06 Lxy0415

make: nasm: Command not found Do you have nasm installed on your environment?

kanzhu-cisco avatar Aug 30 '21 08:08 kanzhu-cisco

@Lxy0415 this command line is not correct: make OS=linux ARCH=aarch64 CC=aarch64-linux-gnu-gcc CXX=aarch64-linux-gnu-g++ -j8

please replace ARCH=aarch64 with ARCH=arm64

GuangweiWang avatar Aug 31 '21 01:08 GuangweiWang

@Lxy0415 this command line is not correct: make OS=linux ARCH=aarch64 CC=aarch64-linux-gnu-gcc CXX=aarch64-linux-gnu-g++ -j8

please replace ARCH=aarch64 with ARCH=arm64

I modified the compile command as you suggested, but got the same error.

My workaround is

# hack: delete build/x86-common.mk
RUN wget https://github.com/cisco/openh264/archive/refs/tags/v1.6.0.tar.gz \
    && tar xzvf v1.6.0.tar.gz \
    && cd openh264-1.6.0 \
    && echo "" > build/x86-common.mk \
    && make OS=linux ARCH=aarch64 CC=aarch64-linux-gnu-gcc CXX=aarch64-linux-gnu-g++ -j8 \
    && make instal

Lxy0415 avatar Aug 31 '21 02:08 Lxy0415

workaround is not recommend. it may cause crash or other error.

I want to double check, you want to build a Linux-arm64 binary, and your command line is: make OS=linux ARCH=arm64 CC=xx CXX=xx -j8 ?

GuangweiWang avatar Aug 31 '21 02:08 GuangweiWang

workaround is not recommend. it may cause crash or other error.

I want to double check, you want to build a Linux-arm64 binary, and your command line is: make OS=linux ARCH=arm64 CC=xx CXX=xx -j8 ?

Yes, you can reproduce it with my dockerfile and cmake config

$ cat arm64.cmake 
set(CMAKE_SYSTEM_NAME Linux)
set(CMAKE_SYSTEM_PROCESSOR aarch64)

set(CMAKE_C_COMPILER "/usr/bin/aarch64-linux-gnu-gcc")
set(CMAKE_CXX_COMPILER "/usr/bin/aarch64-linux-gnu-g++")

set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY)

Lxy0415 avatar Aug 31 '21 02:08 Lxy0415

cmake ? but openh264 does not support cmake now.

GuangweiWang avatar Aug 31 '21 02:08 GuangweiWang

in your previous description, you use this command line to build: make OS=linux ARCH=aarch64 CC=xx CXX=xx -j8

GuangweiWang avatar Aug 31 '21 02:08 GuangweiWang

Just skip the cmake part

$ cat build-debian-stretch-aarch64.Dockerfile 
FROM debian:stretch

LABEL maintainer="[email protected]"
ENV DEBIAN_FRONTEND noninteractive
ENV TZ=Asia/Shanghai

RUN dpkg --add-architecture arm64 && apt-get update

RUN apt-get update && apt-get install -y \
                            crossbuild-essential-arm64 \
                            automake \
                            libtool \
                            pkg-config \
                            apt-utils \
                            openssh-server \
                            rsync \
                            git \
                            vim \
                            wget \
                            sshpass \
                            unzip \
                            ca-certificates \
                            --no-install-recommends

RUN apt-get install -y \
        libvpx-dev:arm64 \
        libx264-dev:arm64 \
        libfreetype6-dev:arm64 \
        --no-install-recommends

RUN wget https://github.com/cisco/openh264/archive/refs/tags/v1.6.0.tar.gz \
    && tar xzvf v1.6.0.tar.gz \
    && cd openh264-1.6.0 \
    && make OS=linux ARCH=arm64 CC=aarch64-linux-gnu-gcc CXX=aarch64-linux-gnu-g++ -j8 \
    && make install

RUN echo "root:123456"|chpasswd
RUN sed -i s/PermitRootLogin\ prohibit-password/PermitRootLogin\ yes/g /etc/ssh/sshd_config
RUN sed -i s/#PermitRootLogin/PermitRootLogin/g /etc/ssh/sshd_config
ENTRYPOINT service ssh restart && bash

Lxy0415 avatar Aug 31 '21 02:08 Lxy0415

FROM debian:stretch

LABEL maintainer="[email protected]" ENV DEBIAN_FRONTEND noninteractive ENV TZ=Asia/Shanghai

RUN dpkg --add-architecture arm64
&& apt-get upgrade
&& apt-get update

RUN apt-get update && apt-get install -y
crossbuild-essential-arm64
automake
libtool
pkg-config
apt-utils
openssh-server
rsync
git
vim
wget
sshpass
unzip
ca-certificates
make
g++
g++-aarch64-linux-gnu
gcc-aarch64-linux-gnu
binutils-aarch64-linux-gnu
--no-install-recommends

RUN apt-get install -y
libvpx-dev:arm64
libx264-dev:arm64
libfreetype6-dev:arm64
--no-install-recommends

RUN wget http://www.nasm.us/pub/nasm/releasebuilds/2.14.02/nasm-2.14.02.tar.bz2
&& tar xfj nasm-2.14.02.tar.bz2
&& cd nasm-2.14.02
&& ./autogen.sh
&& ./configure
&& make
&& make install

RUN wget https://github.com/cisco/openh264/archive/refs/tags/v1.6.0.tar.gz
&& tar xzvf v1.6.0.tar.gz
&& cd openh264-1.6.0
&& make OS=linux ARCH=arm64 CC=aarch64-linux-gnu-gcc CXX=aarch64-linux-gnu-g++ -j8
&& make install

RUN echo "root:123456"|chpasswd RUN sed -i s/PermitRootLogin\ prohibit-password/PermitRootLogin\ yes/g /etc/ssh/sshd_config RUN sed -i s/#PermitRootLogin/PermitRootLogin/g /etc/ssh/sshd_config ENTRYPOINT service ssh restart && bash

kanzhu-cisco avatar Sep 14 '21 02:09 kanzhu-cisco

@Lxy0415, I add nasm and gcc/g++ in you docker file, got some other failure,

/usr/bin/ld: codec/encoder/core/src/au_set.o: Relocations in generic ELF (EM: 183) /usr/bin/ld: codec/encoder/core/src/au_set.o: Relocations in generic ELF (EM: 183) codec/encoder/core/src/au_set.o: error adding symbols: File in wrong format collect2: error: ld returned 1 exit status

May have some other issue in your docker file, please help to check that. We never try build our library in docker environment, and we are pleased if you can make it success.

kanzhu-cisco avatar Sep 14 '21 02:09 kanzhu-cisco

@kanzhu-cisco, Here is cross platform compilation, and the target platform is arm, not x86

Lxy0415 avatar Sep 14 '21 02:09 Lxy0415

yes we need gcc-aarch64-linux-gnu and g++-aarch64-linux-gnu, but it failed with "no g++ found", so I add "apt install g++"

kanzhu-cisco avatar Sep 14 '21 05:09 kanzhu-cisco

Will close this if no update.

huili2 avatar Dec 13 '22 01:12 huili2