VisionWorks Toolkit Reference

April 8, 2016 | 1.4 Release

 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
user_guide_linux.md
Go to the documentation of this file.
1 <!-- Copyright (c) 2014-2016, NVIDIA CORPORATION. All rights reserved. -->
2 
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
6 @{
7 
8 There are 2 methods you can use to build the sample applications and demos:
9 
10 - [Native Build](#Native) &mdash; 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.
14 
15 - [Cross-compilation Build](#Cross) &mdash; 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.
19 
20 <a name="Native">
21 ## Native Compilation of Sample Applications and Demos ##
22 
23 Sources for all samples and demos are provided in the `libvisionworks-samples` 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.
29 
30  $ /usr/share/visionworks/sources/install-samples.sh ~/
31  $ cd ~/VisionWorks-<ver>-Samples/
32  $ make -j4 # add dbg=1 to make debug build
33 
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.
37 
38 <a name="Cross">
39 ## Cross-Compilation of Sample Apps and Demos for Vibrante Linux ##
40 
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.
48 
49 ### Prerequisites
50 
51 Ensure you have met the following prerequisites before cross-compiling the sample applications and demos.
52 
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`, `libvisionworks-dev`, `libvisionworks-nvxio`, `libvisionworks-nvxio-dev` and `libvisionworks-samples`
62  packages are installed on the device.
63 
64 - You have located the sources for the sample applications in the `libvisionworks-samples` package at:
65 
66  /usr/share/visionworks/sources
67 
68  And copied it to a directory with write access before building. For example:
69 
70  $ ~/jetson/usr/share/visionworks/sources/install-samples.sh ~/
71  $ cd ~/VisionWorks-<ver>-Samples/
72 
73 ### To cross-compile sample applications and demos
74 
75 1. [Optional] If OpenCV is installed on your device, copy the `opencv.pc` file from the sample applications
76  folder to the following location on the device:
77 
78  /usr/lib/pkgconfig
79 
80  You overwrite the existing file in this step.
81  You must use `sudo` for this operation because root owns the target file,
82  and the command must be executed on device, not the host computer.
83 
84  $ sudo cp -f /usr/share/visionworks/sources/opencv.pc /usr/lib/pkgconfig
85 
86 2. Add Vibrante PDK cross compiler to your PATH environment variable:
87 
88  $ export PATH=~/toolchains/tegra-4.8.1-nv/usr/bin/armv7a-vfpv3-cortex_a15-linux-gnueabi:$PATH
89 
90  If you cross-compile for aarch64, use:
91 
92  $ export PATH=~/toolchains/tegra-4.9-nv/usr/bin/aarch64-gnu-linux:$PATH
93 
94 3. Add path to Vibrante cross-compiler sysroot to the environment:
95 
96  $ export VIBRANTE_TOOLCHAIN_SYSROOT=~/toolchains/tegra-[version]-nv/usr/sysroot
97 
98 4. Run the following command in the shell to change the configuration of `pkg-config` for cross-compilation:
99 
100  $ export PKG_CONFIG_SYSROOT_DIR=~/jetson
101  $ export PKG_CONFIG_ALLOW_SYSTEM_CFLAGS=1
102  $ export PKG_CONFIG_ALLOW_SYSTEM_LIBS=1
103 
104  Add the following commands if you cross-compile for armv7:
105 
106  $ export PKG_CONFIG_PATH=$PKG_CONFIG_SYSROOT_DIR/usr/lib/arm-linux-gnueabihf/pkgconfig:$PKG_CONFIG_SYSROOT_DIR/usr/lib/pkgconfig
107  $ export PKG_CONFIG_LIBDIR=$PKG_CONFIG_SYSROOT_DIR/usr/share/pkgconfig/
108  $ export CC=arm-cortex_a15-linux-gnueabi-gcc
109  $ export CXX=arm-cortex_a15-linux-gnueabi-g++
110  $ export CPP=arm-cortex_a15-linux-gnueabi-cpp
111  $ export LD=arm-cortex_a15-linux-gnueabi-ld
112  $ export AR=arm-cortex_a15-linux-gnueabi-ar
113 
114  Add the following for cross-compilation for aarch64:
115 
116  $ export PKG_CONFIG_PATH=$PKG_CONFIG_SYSROOT_DIR/usr/lib/aarch64-linux-gnu/pkgconfig:$PKG_CONFIG_SYSROOT_DIR/usr/lib/pkgconfig
117  $ export PKG_CONFIG_LIBDIR=$PKG_CONFIG_SYSROOT_DIR/usr/share/pkgconfig/
118  $ export CC=aarch64-gnu-linux-gcc
119  $ export CXX=aarch64-gnu-linux-g++
120  $ export CPP=aarch64-gnu-linux-cpp
121  $ export LD=aarch64-gnu-linux-ld
122  $ export AR=aarch64-gnu-linux-ar
123 
124  Execute the following commands to build for ARMv7:
125 
126  $ make ARCH=armhf ARMv7=1 -j4 # add dbg=1 to make debug build
127 
128  Execute the following command to build for ARMv8:
129 
130  $ make ARCH=aarch64 ARMv8=1 -j4 # add dbg=1 to make debug build
131 
132 ## Running Samples and Demos ##
133 
134 **Applies to:** ARM devices only. Start the X window manager:
135 
136  $ export DISPLAY=:0
137  $ X -ac &
138  $ blackbox $
139 
140 Go to the samples directory:
141 
142  $ cd ~/VisionWorks-<ver>-Samples/sources/bin/[arch]/linux/release
143 
144 Run each sample of interest by using the name of the sample. For example, to run `nvx_demo_feature_tracker`, execute:
145 
146  $ ./nvx_demo_feature_tracker
147 
148 @}