跳转到内容
STAGING SERVER
DEVELOPMENT SERVER

Cross-Development#

This topic explains the Debian Multiarch feature for cross-development.

Debian Multiarch#

The Debian project maintains package repositories for several computer architectures, including AMD64 and ARM64. These are relevant for cross-development targeting ARM64 devices like the Smart blaze from an AMD64 development host. On Debian, packages for both architectures are available from the same repository URL, making it convenient to install packages for different architectures as build dependencies.

信息

On Ubuntu, ARM64 repositories are located in the separate ubuntu-ports repository.

With the Multiarch feature, you can install packages for foreign architectures to use with a cross toolchain. The -dev variants of library packages are typically the most relevant, because they provide the headers and libraries needed to build against those packages. For debugging, you can also install debug symbols (-dbg or -dbgsym) and, separately, the corresponding source packages.

The cross-development toolchain is provided by the crossbuild-essential-arm64 package.

Native Development#

For application development, it's most convenient to build and test your application natively on the target VM (or another ARM64 machine) first, then cross-compile from your AMD64 development host.

Cross-Building Using Docker Container#

The Multiarch concepts above are demonstrated in the Docker container for cross-builds included in the Smart blaze SDK. The container includes the cross-development toolchain, development files for the pylon SDK, and the pylon Supplementary Package for blaze. The container is preconfigured with a CMake toolchain file for cross-building ARM64 executables. For setting up the container, see Docker Container for Development.

To build your own software, extend the Dockerfile to install the required <packagename>-dev:arm64 dependencies. In most cases, these can be integrated using the corresponding find_package call in CMake. For example, the Docker container includes the libopencv-dev package. In the blaze sample CMakeLists.txt files, you will find the following call:

find_package(OpenCV)

Use the ${OpenCV_INCLUDE_DIRS} variable with target_include_directories()${OpenCV_LIBS} variable with target_link_libraries(). Some packages, such as Boost, also export a CMake target. In that case, it's sufficient to link against the target in target_link_libraries(), which automatically configures include paths as well.

If your dependencies aren't available as Debian packages but provide CMake support, build them from source using the FetchContent module. In this case, install the required build dependencies in the Docker container as described in the project's documentation. If the library doesn't support CMake, you can use the more general ExternalProject module.

Docker Container for Development#

To develop software for the camera, you can set up a Docker container that contains the cross-development toolchain and all required packages.

To install the Docker engine, follow the instructions at docs.docker.com.

Building the Smart blaze Development Container#

With this release, you have received an archive containing a Dockerfile. In the extracted archive, go to the directory that contains the Dockerfile. To build the container, run the following command in a terminal:

docker build -t blaze-dev --build-arg UID=$(id -u) --build-arg GID=$(id -g) .

This creates a Debian container with the cross toolchain, the pylon SDK for blaze, and a suitable CMake configuration for cross-compilation.

Running Commands in the Docker Container#

To run commands inside the development container, create the following alias:

alias dockerDo='docker run --rm -ti --volume $(pwd):/work --workdir /work blaze-dev'

For convenience, you can add this line to your ~/.bashrc file.

即: dockerDo alias mounts the current working directory into a temporary container and executes the command given after dockerDo inside the container. The mounted directory is used as the working directory for the command. The command is executed inside the container with the user ID matching the user who built the container (which should be the current user). This avoids permission problems with files created inside the container.

示例:

dockerDo cmake -B build .
dockerDo cmake --build build -j$(nproc)

信息

The container already defines the environment variable CMAKE_TOOLCHAIN_FILE, which instructs CMake to use the ARM64 cross-compiler toolchain included in the development container.

Cross-Building Using ELBE SDK (Embedded Linux Build Environment)#

To avoid Docker containers and duplicated package data for the rootfs and cross-build environment, a Yocto-style SDK can be created from elbe/blazevm.xml, the same source as for the rootfs. For more information, see Building an SDK with ELBE.

For CMake projects, use the ELBE SDK as shown below for a blaze sample project. Adjust the CMake toolchain file path to match your installation. If you are using the extracted Smart blaze SDK rather than the pylon samples tree, the toolchain file is typically under elbe/cross-toolchain.cmake in that SDK directory.

cd /opt/pylon/share/pylon/Samples/blaze/cpp/FirstSample/
. /opt/elbe-sdk-aarch64-linux-gnu-BlazeVM-1.2/environment-setup-elbe-aarch64-linux-gnu-BlazeVM-1.2
export CMAKE_TOOLCHAIN_FILE=/opt/pylon/share/pylon/Samples/blaze/smartblaze/vm/elbe/cross-toolchain.cmake
cmake -B build .
cmake --build build -j$(nproc)

Managing the VM on the Camera#

Once you have configured internet access for your VM, you can install packages using apt-getpip install. Alternatively, you can extend the elbe/blazevm.xml config file to build a new root filesystem from scratch.

Runtime Libraries on the Target VM

When you build software with the Docker container or the ELBE SDK and install it on the VM, ensure that all runtime dependencies are present. For every <packagename>-dev:arm64 package you installed in the cross-build environment, install the corresponding library package in the target root filesystem. For OpenCV, the required packages are split into modules. For the blaze samples, you need libopencv-calib3d, libopencv-core, libopencv-highgui, libopencv-imgcodecs, and libopencv-imgproc.