raspberrypi / userland

Source code for ARM side libraries for interfacing to Raspberry Pi GPU.
BSD 3-Clause "New" or "Revised" License
2.05k stars 1.09k forks source link

Cross compilation w/ Docker fails #615

Open rolandjitsu opened 4 years ago

rolandjitsu commented 4 years ago

Describe the bug I'm trying to build a binary that uses the go-mmal package (mmal bindings for Go) using a Docker image:

FROM golang:1.13

RUN apt-get update \
  && apt-get install -y gcc-arm-linux-gnueabihf g++-arm-linux-gnueabihf libssl-dev

RUN wget https://github.com/Kitware/CMake/releases/download/v3.16.4/cmake-3.16.4.tar.gz \
  && tar -xzvf cmake-3.16.4.tar.gz \
  && cd cmake-3.16.4 \
  && ./bootstrap \
  && make -j$(nproc) \
  && make install \
  && cmake --version

ENV BUILDTYPE=Release
ENV BUILDSUBDIR=release
ENV ARM64=OFF
ENV CMAKE_TOOLCHAIN_FILE=../../../makefiles/cmake/toolchains/arm-linux-gnueabihf.cmake

# RUN git clone https://github.com/raspberrypi/userland.git /rpi-sc \
#   && cd /rpi-sc \
#   && git checkout 06bc6da \
#   && ./buildme --native

RUN git clone https://github.com/raspberrypi/userland.git /rpi-sc \
  && cd /rpi-sc \
  && git checkout 06bc6da \
  && mkdir -p build/arm-linux/$BUILDSUBDIR \
  && cd build/arm-linux/$BUILDSUBDIR \
  && cmake -DT_NEEDED=ON -DCMAKE_TOOLCHAIN_FILE=$CMAKE_TOOLCHAIN_FILE -DCMAKE_BUILD_TYPE=$BUILDTYPE -DARM64=$ARM64 ../../.. \
  && make -j `nproc` \
  && make install

RUN uname -a
docker run --rm -v $CWD/tmp/go/pkg/mod:/go/pkg/mod -v "$CWD":/code -w /code \
    -e PKG_CONFIG_PATH=/rpi-sc/build/arm-linux/release \
    -e CC=arm-linux-gnueabihf-gcc \
    -e CXX=arm-linux-gnueabihf-g++ \
    -e CGO_ENABLED=1 \
    -e GOOS=linux \
    -e GOARCH=arm \
    go-arm go build -o ./bin/camera ./cmd/camera/main.go

But while building the Go binary, I get the following error:

/usr/lib/gcc-cross/arm-linux-gnueabihf/8/../../../../arm-linux-gnueabihf/bin/ld: warning: libmmal_components.so, needed by /opt/vc/lib/libmmal.so, not found (try using -rpath or -rpath-link)
/usr/lib/gcc-cross/arm-linux-gnueabihf/8/../../../../arm-linux-gnueabihf/bin/ld: warning: libvchiq_arm.so, needed by /opt/vc/lib/libmmal.so, not found (try using -rpath or -rpath-link)
/usr/lib/gcc-cross/arm-linux-gnueabihf/8/../../../../arm-linux-gnueabihf/bin/ld: warning: libcontainers.so, needed by /opt/vc/lib/libmmal.so, not found (try using -rpath or -rpath-link)
/usr/lib/gcc-cross/arm-linux-gnueabihf/8/../../../../arm-linux-gnueabihf/bin/ld: /opt/vc/lib/libbcm_host.so: undefined reference to `single_get_func_table'
/usr/lib/gcc-cross/arm-linux-gnueabihf/8/../../../../arm-linux-gnueabihf/bin/ld: /opt/vc/lib/libbcm_host.so: undefined reference to `vchi_service_release'
/usr/lib/gcc-cross/arm-linux-gnueabihf/8/../../../../arm-linux-gnueabihf/bin/ld: /opt/vc/lib/libmmal_vc_client.so: undefined reference to `vchiq_connect'
/usr/lib/gcc-cross/arm-linux-gnueabihf/8/../../../../arm-linux-gnueabihf/bin/ld: /opt/vc/lib/libmmal_vc_client.so: undefined reference to `vchiq_initialise_fd'
/usr/lib/gcc-cross/arm-linux-gnueabihf/8/../../../../arm-linux-gnueabihf/bin/ld: /opt/vc/lib/libbcm_host.so: undefined reference to `vchiq_initialise'
/usr/lib/gcc-cross/arm-linux-gnueabihf/8/../../../../arm-linux-gnueabihf/bin/ld: /opt/vc/lib/libmmal_vc_client.so: undefined reference to `vchiq_release_service'
/usr/lib/gcc-cross/arm-linux-gnueabihf/8/../../../../arm-linux-gnueabihf/bin/ld: /opt/vc/lib/libmmal_vc_client.so: undefined reference to `vchiq_release_message'
/usr/lib/gcc-cross/arm-linux-gnueabihf/8/../../../../arm-linux-gnueabihf/bin/ld: /opt/vc/lib/libbcm_host.so: undefined reference to `vchi_service_open'
/usr/lib/gcc-cross/arm-linux-gnueabihf/8/../../../../arm-linux-gnueabihf/bin/ld: /opt/vc/lib/libmmal_vc_client.so: undefined reference to `vchiq_use_service'
/usr/lib/gcc-cross/arm-linux-gnueabihf/8/../../../../arm-linux-gnueabihf/bin/ld: /opt/vc/lib/libbcm_host.so: undefined reference to `vchi_msg_dequeue'
/usr/lib/gcc-cross/arm-linux-gnueabihf/8/../../../../arm-linux-gnueabihf/bin/ld: /opt/vc/lib/libmmal_vc_client.so: undefined reference to `vchiq_queue_message'
/usr/lib/gcc-cross/arm-linux-gnueabihf/8/../../../../arm-linux-gnueabihf/bin/ld: /opt/vc/lib/libbcm_host.so: undefined reference to `vchi_service_close'
/usr/lib/gcc-cross/arm-linux-gnueabihf/8/../../../../arm-linux-gnueabihf/bin/ld: /opt/vc/lib/libbcm_host.so: undefined reference to `vchi_msg_queue'
/usr/lib/gcc-cross/arm-linux-gnueabihf/8/../../../../arm-linux-gnueabihf/bin/ld: /opt/vc/lib/libbcm_host.so: undefined reference to `vchi_mphi_message_driver_func_table'
/usr/lib/gcc-cross/arm-linux-gnueabihf/8/../../../../arm-linux-gnueabihf/bin/ld: /opt/vc/lib/libbcm_host.so: undefined reference to `vchi_initialise'
/usr/lib/gcc-cross/arm-linux-gnueabihf/8/../../../../arm-linux-gnueabihf/bin/ld: /opt/vc/lib/libbcm_host.so: undefined reference to `vchi_bulk_queue_receive'
/usr/lib/gcc-cross/arm-linux-gnueabihf/8/../../../../arm-linux-gnueabihf/bin/ld: /opt/vc/lib/libbcm_host.so: undefined reference to `vchi_msg_queuev'
/usr/lib/gcc-cross/arm-linux-gnueabihf/8/../../../../arm-linux-gnueabihf/bin/ld: /opt/vc/lib/libmmal_vc_client.so: undefined reference to `vchiq_shutdown'
/usr/lib/gcc-cross/arm-linux-gnueabihf/8/../../../../arm-linux-gnueabihf/bin/ld: /opt/vc/lib/libbcm_host.so: undefined reference to `vchi_service_use'
/usr/lib/gcc-cross/arm-linux-gnueabihf/8/../../../../arm-linux-gnueabihf/bin/ld: /opt/vc/lib/libmmal_vc_client.so: undefined reference to `vchiq_queue_bulk_receive'
/usr/lib/gcc-cross/arm-linux-gnueabihf/8/../../../../arm-linux-gnueabihf/bin/ld: /opt/vc/lib/libmmal_vc_client.so: undefined reference to `vchiq_queue_bulk_transmit'
/usr/lib/gcc-cross/arm-linux-gnueabihf/8/../../../../arm-linux-gnueabihf/bin/ld: /opt/vc/lib/libbcm_host.so: undefined reference to `vchi_bulk_queue_transmit'
/usr/lib/gcc-cross/arm-linux-gnueabihf/8/../../../../arm-linux-gnueabihf/bin/ld: /opt/vc/lib/libmmal_vc_client.so: undefined reference to `vchiq_open_service'
/usr/lib/gcc-cross/arm-linux-gnueabihf/8/../../../../arm-linux-gnueabihf/bin/ld: /opt/vc/lib/libmmal_vc_client.so: undefined reference to `vchiq_close_service'
/usr/lib/gcc-cross/arm-linux-gnueabihf/8/../../../../arm-linux-gnueabihf/bin/ld: /opt/vc/lib/libbcm_host.so: undefined reference to `vchi_connect'
/usr/lib/gcc-cross/arm-linux-gnueabihf/8/../../../../arm-linux-gnueabihf/bin/ld: /opt/vc/lib/libbcm_host.so: undefined reference to `vchi_create_connection'

To reproduce Try to build a simple Go bin that uses the package I linked above with the Docker image and cmd I've added above.

Expected behaviour I should be able to cross compile the Go binary without issues.

Actual behaviour It fails with the error described above.

System I'm building this on a macOS using Docker.

Docker image uname -a:

Linux b5cc0422e693 4.19.76-linuxkit #1 SMP Thu Oct 17 19:31:58 UTC 2019 x86_64 GNU/Linux

Distro cat /etc/os-release:

PRETTY_NAME="Debian GNU/Linux 10 (buster)"
NAME="Debian GNU/Linux"
VERSION_ID="10"
VERSION="10 (buster)"
VERSION_CODENAME=buster
ID=debian
HOME_URL="https://www.debian.org/"
SUPPORT_URL="https://www.debian.org/support"
BUG_REPORT_URL="https://bugs.debian.org/"

Logs If applicable, add the relevant output from dmesg or similar.

Additional context Add any other relevant context for the problem.

bartvanarnhem commented 4 years ago

For anyone stumbling upon this ticket:

I was facing this exact issue trying to cross-compile an application that uses go-mmal for the Raspberry Pi 3 inside a Docker. For me the fix was to add -lvchiq_arm -lmmal_components -lcontainers to the pkg-config file (mmal.pc) inside /opt/vc/lib/pkgconfig/mmal.pc, which now looks like:

$ cat /opt/vc/lib/pkgconfig/mmal.pc
prefix=/opt/vc
exec_prefix=${prefix}
libdir=${exec_prefix}/lib
includedir=${prefix}/include

Name: MMAL
Description: Multi-Media Abstraction Layer library for RPi
Version: 1
Requires: vcsm
Libs: -L${libdir} -lmmal -lmmal_core -lmmal_util -lmmal_vc_client -lbcm_host -lvchiq_arm -lmmal_components -lcontainers
Cflags: -I${includedir}