1 <!-- Copyright (c) 2014-2015, NVIDIA CORPORATION. All rights reserved. -->
3 @defgroup nvx_sample_building_linux Linux: Building and Running Samples and Demos
4 @brief Shows how to build samples and demos
using native or cross compilation on Linux.
5 @ingroup nvx_samples_and_demos_user_guides
8 There are 2 methods you can use to build the sample applications and demos:
10 - [Native Build](#Native) — Native compilation is easiest,
11 but x86 desktops are faster at compilation than ARM devices,
12 so
if you are targeting an ARM device it might be worth cross-compiling
13 from an x86 desktop instead of native-compiling on the device.
15 - [Cross-compilation Build](#Cross) — Cross-compilation is faster,
16 but requires some additional configuration. Cross-compilation also requires
17 that you have mounted the device
's file system onto your host computer. You can
18 use the `sshfs` tool, NFS file system, or plug a flash card into your computer.
21 ## Native Compilation of Sample Applications and Demos ##
23 Sources for all samples and demos are provided in the `libvisionworks-dev` package.
24 After the package installation, source code and make files are located in the
25 `/usr/share/visionworks/sources` directory. The directory is protected from changes,
26 so you need to copy its content to any directory with write access.
27 Here we use your home folder as an example.
28 All samples use `make` as a build tool.
30 $ /usr/share/visionworks/sources/install-samples.sh ~/
31 $ cd ~/VisionWorks-<ver>-Samples/
32 $ make -j4 # add dbg=1 to make debug build
34 You can build an individual sample from its directory but the executable will
35 not be created there nor in a sub-directory. The executable is created in the same directory
36 as when all samples are built from the top-level directory.
39 ## Cross-Compilation of Sample Apps and Demos for Vibrante Linux ##
41 You use the same source code and `make` files when cross-compiling as you do for native builds,
42 but you also need the cross-compiler toolchain and a mounted device file system.
43 All samples use `make` as the build tool, but you must provide additional options
44 to configure `pkg-config` and the cross-compiler.
45 In addition, sample applications can use OpenCV and you should make some modifications
46 to the OpenCV files to enable cross-compiler support, but this step is optional.
47 This topic describes the steps to follow to cross-compile the sample applications.
51 Ensure you have met the following prerequisites before cross-compiling the sample applications and demos.
53 - The device file system is available to be used directly from a flash card
54 or mounted to the host file system via `sshfs` or NFS.
55 **Note:** It is important to transform absolute symlinks to relative (e.g., use `sshfs -o transform_symlinks <src> <dst>`)
56 The procedure below assumes the device file system has been mounted to `~/jetson`.
57 - You have a Vibrante PDK toolchain installed with the same version as Vibrante installed on the device.
58 If you do not, reinstall either `vibrante-vcm30t124-linux-<version>-oss-minimal-pdk.run` or
59 `vibrante-t210ref-foundation-<version>-toolchain.run` package and approve toolchain installation.
60 The procedure below assumes the Vibrante PDK toolchains are installed to `~/toolchains`.
61 - `libvisionworks` and `libvisionworks-dev` packages are installed on the device.
63 - You have located the sources for the sample applications in the libvisionworks-dev package at:
65 /usr/share/visionworks/sources
67 And copied it to a directory with write access before building. For example:
69 $ ~/jetson/usr/share/visionworks/sources/install-samples.sh ~/
70 $ cd ~/VisionWorks-<ver>-Samples/
72 ### To cross-compile sample applications and demos
74 1. [Optional] If OpenCV is installed on your device, copy the `opencv.pc` file from the sample applications
75 folder to the following location on the device:
79 You overwrite the existing file in this step.
80 You must use `sudo` for this operation because root owns the target file,
81 and the command must be executed on device, not the host computer.
83 $ sudo cp -f /usr/share/visionworks/sources/opencv.pc /usr/lib/pkgconfig
85 2. Add Vibrante PDK cross compiler to your PATH environment variable:
87 $ export PATH=~/toolchains/tegra-4.8.1-nv/usr/bin/armv7a-vfpv3-cortex_a15-linux-gnueabi:$PATH
89 If you cross-compile for aarch64, use:
91 $ export PATH=~/toolchains/tegra-4.9-nv/usr/bin/aarch64-gnu-linux:$PATH
93 3. Add path to Vibrante cross-compiler sysroot to the environment:
95 $ export VIBRANTE_TOOLCHAIN_SYSROOT=~/toolchains/tegra-[version]-nv/usr/sysroot
97 4. Run the following command in the shell to change the configuration of `pkg-config` for cross-compilation:
99 $ export PKG_CONFIG_SYSROOT_DIR=~/jetson
100 $ export PKG_CONFIG_ALLOW_SYSTEM_CFLAGS=1
101 $ export PKG_CONFIG_ALLOW_SYSTEM_LIBS=1
103 Add the following commands if you cross-compile for armv7:
105 $ export PKG_CONFIG_PATH=$PKG_CONFIG_SYSROOT_DIR/usr/lib/arm-linux-gnueabihf/pkgconfig:$PKG_CONFIG_SYSROOT_DIR/usr/lib/pkgconfig
106 $ export PKG_CONFIG_LIBDIR=$PKG_CONFIG_SYSROOT_DIR/usr/share/pkgconfig/
107 $ export CC=arm-cortex_a15-linux-gnueabi-gcc
108 $ export CXX=arm-cortex_a15-linux-gnueabi-g++
109 $ export CPP=arm-cortex_a15-linux-gnueabi-cpp
110 $ export LD=arm-cortex_a15-linux-gnueabi-ld
111 $ export AR=arm-cortex_a15-linux-gnueabi-ar
113 Add the following for cross-compilation for aarch64:
115 $ export PKG_CONFIG_PATH=$PKG_CONFIG_SYSROOT_DIR/usr/lib/aarch64-linux-gnu/pkgconfig:$PKG_CONFIG_SYSROOT_DIR/usr/lib/pkgconfig
116 $ export PKG_CONFIG_LIBDIR=$PKG_CONFIG_SYSROOT_DIR/usr/share/pkgconfig/
117 $ export CC=aarch64-gnu-linux-gcc
118 $ export CXX=aarch64-gnu-linux-g++
119 $ export CPP=aarch64-gnu-linux-cpp
120 $ export LD=aarch64-gnu-linux-ld
121 $ export AR=aarch64-gnu-linux-ar
123 Execute the following commands to build for ARMv7:
125 $ make ARCH=armhf ARMv7=1 -j4 # add dbg=1 to make debug build
127 Execute the following command to build for ARMv8:
129 $ make ARCH=aarch64 ARMv8=1 -j4 # add dbg=1 to make debug build
131 ## Running Samples and Demos ##
133 **Applies to:** ARM devices only. Start the X window manager:
139 Go to the samples directory:
141 $ cd ~/VisionWorks-<ver>-Samples/sources/bin/[arch]/linux/release
143 Run each sample of interest by using the name of the sample. For example, to run `nvx_demo_feature_tracker`, execute:
145 $ ./nvx_demo_feature_tracker