| <html><head><meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"><title>3.6. Using Sourcery G++ Lite on GNU/Linux Targets</title><link rel="stylesheet" href="cs.css" type="text/css"><meta name="generator" content="DocBook XSL Stylesheets V1.74.0"><link rel="home" href="index.html" title="Sourcery G++ Lite"><link rel="up" href="chap-target.html" title="Chapter 3. Sourcery G++ Lite for ARM GNU/Linux"><link rel="prev" href="sec-dynamic-loader-version.html" title="3.5. Target Dynamic Loader Requirements"><link rel="next" href="linux-gdbserver.html" title="3.7. Using GDB Server for Debugging"></head><body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><div class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="3" align="center">3.6. Using Sourcery G++ Lite on GNU/Linux Targets</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="sec-dynamic-loader-version.html">Prev</a> </td><th width="60%" align="center">Chapter 3. Sourcery G++ Lite for ARM GNU/Linux</th><td width="20%" align="right"> <a accesskey="n" href="linux-gdbserver.html">Next</a></td></tr></table><hr></div><div class="section" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="included-libraries"></a>3.6. Using Sourcery G++ Lite on GNU/Linux Targets</h2></div></div></div><p> |
| In order to run and debug programs produced by Sourcery G++ on a GNU/Linux |
| target, you must install runtime support files on the target. You may also |
| need to set appropriate build options so that your executables can find |
| the correct dynamic linker and libraries at runtime. |
| |
| </p><p> |
| The runtime support files, referred to as the <em class="firstterm">sysroot</em>, |
| are found in the <code class="filename">arm-none-linux-gnueabi/libc</code> directory of your |
| Sourcery G++ Lite installation. The sysroot consists of the contents of the |
| <code class="filename">etc</code>, <code class="filename">lib</code>, <code class="filename">sbin</code>, |
| and <code class="filename">usr</code> directories. |
| <span> |
| There may be other directories in <code class="filename">arm-none-linux-gnueabi/libc</code> |
| that contain additional sysroots customized for particular combinations of |
| command-line compiler flags, or <em class="firstterm">multilibs</em>. |
| Refer to <a class="xref" href="sec-multilibs.html" title="3.2. Library Configurations">Section 3.2, “Library Configurations”</a> for a list of the included multilibs |
| in this version of Sourcery G++ Lite, and the corresponding sysroot directory |
| pathnames. |
| </span> |
| </p><div class="note" style="margin-left: 0.5in; margin-right: 0.5in;"><h3 class="title">Note for Windows Host Users</h3><p> |
| The |
| |
| sysroots provided in Windows host packages for Sourcery G++ are not |
| directly usable on the GNU/Linux target |
| because of differences between the |
| Windows and GNU/Linux file systems. |
| Some files that are hard links, or copies, in the sysroot |
| as installed on the Windows file system should be symbolic links |
| on the GNU/Linux target. |
| Additionally, some files in the sysroot that should be marked |
| executable on the GNU/Linux target |
| are not marked executable on Windows. |
| If you intend to use the |
| |
| sysroot provided with Sourcery G++ on a |
| Windows host system as the basis for your GNU/Linux target |
| filesystem, |
| you must correct these issues after copying the sysroot to the target. |
| |
| |
| </p></div><p> |
| You have these choices for installing the sysroot on the target: |
| </p><div class="itemizedlist"><ul type="disc"><li><p> |
| You can install the files in the filesystem root on the target |
| (that is, installing the files directly in <code class="filename">/etc/</code>, |
| <code class="filename">/lib/</code>, and so on). All applications on the |
| target then automatically use the Sourcery G++ libraries. |
| This method is primarily useful when you are |
| building a GNU/Linux root filesystem from scratch. |
| If your target board already has a GNU/Linux filesystem installed, |
| overwriting the existing C library files is not recommended, as this |
| may break other applications on your system, or cause it to fail to boot. |
| </p></li><li><p> |
| You can install the sysroot in an alternate location and build your |
| application with the <code class="option">-rpath</code> and |
| <code class="option">--dynamic-linker</code> linker options to specify the sysroot |
| location. |
| </p></li><li><p> |
| You can install the sysroot in an alternate location and explicitly |
| invoke your application through the dynamic linker to specify the |
| sysroot location. |
| If you are just getting started with Sourcery G++ Lite, this may be the easiest |
| way to get your application running, but this method does not support use |
| of the debugger. |
| |
| </p></li></ul></div><p> |
| Setting the environment variable <code class="envar">LD_LIBRARY_PATH</code> |
| on the target is not sufficient, since executables produced by Sourcery G++ |
| depend on the Sourcery G++ dynamic linker included in the sysroot as well |
| as the Sourcery G++ runtime libraries. |
| </p><div class="section" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="sec-installing-sysroot"></a>3.6.1. Installing the Sysroot</h3></div></div></div><p> |
| If you are modifying an existing system, rather than creating a new |
| system from scratch, you should place the sysroot files in a new directory, |
| rather than in the root directory of your target system. |
| </p><p> |
| If you choose to overwrite your existing C library, you may not be |
| able to boot your system. You should back up your existing system |
| before overwriting the C library and ensure that you can restore the |
| backup even with your system offline. |
| </p><p> |
| The next step is to identify the correct sysroot subdirectory |
| in the Sourcery G++ Lite install directory on your host system. |
| The sysroot you copy to the target must be the one that corresponds |
| to the linker options you are using to build your applications. |
| The tables in <a class="xref" href="sec-multilibs.html" title="3.2. Library Configurations">Section 3.2, “Library Configurations”</a> |
| tell you which sysroot subdirectories correspond to which sets of |
| command-line options. |
| |
| From the command line, you can identify the appropriate |
| sysroot for your program by invoking the compiler with |
| <code class="option">-print-sysroot</code> added to your other build options. |
| This causes GCC to print the host sysroot pathname and exit. |
| </p><p> |
| The mechanism you use for copying the sysroot to your target board depends |
| on its hardware and software configuration. |
| You may be able to use FTP or SSH with a server |
| already running on your target. |
| |
| If your target board does not have networking configured, you may be |
| able to copy files using an SD card or USB memory stick, or via a |
| file transfer utility over a serial line. The instructions that come |
| with your board may include specific suggestions. |
| </p><p> |
| When running Sourcery G++ on a GNU/Linux host, as an alternative to |
| copying files to the target system, you may be able to NFS-mount the |
| Sourcery G++ Lite installation directory from your host system on the target |
| system. It is especially convenient for debugging if you can make the |
| sysroot pathname on the target system be identical to that on the |
| GNU/Linux host system; refer to <a class="xref" href="linux-gdbserver.html#sec-gdb-sysroot" title="3.7.3. Setting the Sysroot in the Debugger">Section 3.7.3, “Setting the Sysroot in the Debugger”</a> |
| for further discussion of this issue. |
| </p><p> |
| Otherwise, you must copy files from the |
| <span> |
| appropriate |
| |
| sysroot subdirectory in the |
| </span> |
| <code class="filename">arm-none-linux-gnueabi/libc</code> directory of |
| your Sourcery G++ Lite install to the target system. |
| In many cases, you do not need to copy all of the files in the sysroot. |
| For example, the <code class="filename">usr/include</code> subdirectory contains |
| files that are only needed if you will actually be running the compiler |
| on your target system. You do not need these files for non-native compilers. |
| You also do not need any <code class="filename">.o</code> or <code class="filename">.a</code> |
| files; these are used by the compiler when linking programs, but are not |
| needed to run programs. You should definitely copy all |
| <code class="filename">.so</code> files and the executable files in |
| <code class="filename">usr/bin</code> and <code class="filename">sbin</code>. |
| </p></div><div class="section" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="sec-linker-sysroot"></a>3.6.2. Using Linker Options to Specify the Sysroot Location</h3></div></div></div><p> |
| If you have installed the sysroot on the target in a location other than |
| the file system root, you can use the <code class="option">-rpath</code> and |
| <code class="option">--dynamic-linker</code> linker options to specify the sysroot |
| location. |
| </p><p> |
| If you are using Sourcery G++ from the command line, follow these steps: |
| </p><div class="orderedlist"><ol type="1"><li><p> |
| First find the correct sysroot directory, dynamic linker, and library |
| subdirectory for your |
| selected multilib. Refer to <a class="xref" href="sec-multilibs.html" title="3.2. Library Configurations">Section 3.2, “Library Configurations”</a>. |
| In the following steps, |
| <em class="replaceable"><code>sysroot</code></em> is the absolute path to the |
| sysroot directory on the target corresponding to your selected multilib. |
| For the default multilib, the dynamic linker path relative to the sysroot is |
| <code class="filename">lib/ld-linux.so.3</code>, and the library subdirectory is |
| <code class="filename">lib</code>. |
| This is used in the example below. |
| </p></li><li><p> |
| When invoking <code class="command">arm-none-linux-gnueabi-gcc</code> to link your executable, |
| include the command-line options: |
| |
| </p><pre class="screen">-Wl,-rpath=<em class="replaceable"><code>sysroot</code></em>/lib:<em class="replaceable"><code>sysroot</code></em>/usr/lib \ |
| -Wl,--dynamic-linker=<em class="replaceable"><code>sysroot</code></em>/lib/ld-linux.so.3</pre><p> |
| |
| where <em class="replaceable"><code>sysroot</code></em> is the absolute path to the |
| sysroot directory on the target corresponding to your selected multilib. |
| </p></li><li><p> |
| Copy the executable to the target and execute it normally. |
| </p></li></ol></div><p> |
| Note that if you specify an incorrect path for |
| <code class="option">--dynamic-linker</code>, the common failure mode seen when running |
| your application on the target is similar to |
| </p><pre class="screen">> ./factorial |
| ./factorial: No such file or directory</pre><p> |
| |
| or |
| |
| </p><pre class="screen">> ./factorial |
| ./factorial: bad ELF interpreter: No such file or directory</pre><p> |
| |
| This can be quite confusing since it appears from the error message |
| as if it is the <code class="filename">./factorial</code> executable that is |
| missing rather than the dynamic linker it references. |
| </p></div><div class="section" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="sec-runtime-sysroot"></a>3.6.3. Specifying the Sysroot Location at Runtime</h3></div></div></div><p> |
| You can invoke the Sourcery G++ dynamic linker on the target to run your |
| application without having to compile it with specific linker options. |
| |
| </p><p> |
| To do this, follow these steps: |
| </p><div class="orderedlist"><ol type="1"><li><p> |
| Build your application on the host, without any additional linker options, |
| and copy the executable to your target system. |
| </p></li><li><p> |
| Find the correct sysroot directory, dynamic linker, and library |
| subdirectory for your |
| selected multilib. Refer to <a class="xref" href="sec-multilibs.html" title="3.2. Library Configurations">Section 3.2, “Library Configurations”</a>. |
| In the following steps, |
| <em class="replaceable"><code>sysroot</code></em> is the absolute path to the |
| sysroot directory on the target corresponding to your selected multilib. |
| For the default multilib, the dynamic linker is |
| <code class="filename">lib/ld-linux.so.3</code>, and the library subdirectory is |
| <code class="filename">lib</code>. |
| This is used in the example below. |
| </p></li><li><p> |
| On the target system, invoke the dynamic linker with your executable as: |
| |
| </p><pre class="screen">> <em class="replaceable"><code>sysroot</code></em>/lib/ld-linux.so.3 \ |
| --library-path <em class="replaceable"><code>sysroot</code></em>/lib:<em class="replaceable"><code>sysroot</code></em>/usr/lib \ |
| <em class="replaceable"><code>/path/to/your-executable</code></em></pre><p> |
| |
| where <em class="replaceable"><code>sysroot</code></em> is the absolute path to the |
| sysroot directory on the target corresponding to your selected |
| multilib. |
| </p><p>Invoking the linker in this manner requires that |
| you provide either an absolute pathname to your executable, or a relative |
| pathname prefixed with <code class="filename">./</code>. Specifying only the name |
| of a file in the current directory does not work. |
| </p></li></ol></div></div></div><div class="navfooter"><hr><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="sec-dynamic-loader-version.html">Prev</a> </td><td width="20%" align="center"><a accesskey="u" href="chap-target.html">Up</a></td><td width="40%" align="right"> <a accesskey="n" href="linux-gdbserver.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">3.5. Target Dynamic Loader Requirements </td><td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td><td width="40%" align="right" valign="top"> 3.7. Using GDB Server for Debugging</td></tr></table></div></body></html> |