| Andrew Geissler | f034379 | 2020-11-18 10:42:21 -0600 | [diff] [blame] | 1 | .. SPDX-License-Identifier: CC-BY-SA-2.0-UK | 
| Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 2 |  | 
|  | 3 | ******************************** | 
|  | 4 | Using the SDK Toolchain Directly | 
|  | 5 | ******************************** | 
|  | 6 |  | 
|  | 7 | You can use the SDK toolchain directly with Makefile and Autotools-based | 
|  | 8 | projects. | 
|  | 9 |  | 
|  | 10 | Autotools-Based Projects | 
|  | 11 | ======================== | 
|  | 12 |  | 
| Andrew Geissler | 09209ee | 2020-12-13 08:44:15 -0600 | [diff] [blame] | 13 | Once you have a suitable :ref:`sdk-manual/intro:the cross-development toolchain` | 
| Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 14 | installed, it is very easy to develop a project using the `GNU | 
|  | 15 | Autotools-based <https://en.wikipedia.org/wiki/GNU_Build_System>`__ | 
|  | 16 | workflow, which is outside of the :term:`OpenEmbedded Build System`. | 
|  | 17 |  | 
|  | 18 | The following figure presents a simple Autotools workflow. | 
|  | 19 |  | 
|  | 20 | .. image:: figures/sdk-autotools-flow.png | 
|  | 21 | :align: center | 
|  | 22 |  | 
|  | 23 | Follow these steps to create a simple Autotools-based "Hello World" | 
|  | 24 | project: | 
|  | 25 |  | 
|  | 26 | .. note:: | 
|  | 27 |  | 
|  | 28 | For more information on the GNU Autotools workflow, see the same | 
|  | 29 | example on the | 
|  | 30 | GNOME Developer | 
|  | 31 | site. | 
|  | 32 |  | 
|  | 33 | 1. *Create a Working Directory and Populate It:* Create a clean | 
|  | 34 | directory for your project and then make that directory your working | 
|  | 35 | location. | 
|  | 36 | :: | 
|  | 37 |  | 
|  | 38 | $ mkdir $HOME/helloworld | 
|  | 39 | $ cd $HOME/helloworld | 
|  | 40 |  | 
|  | 41 | After setting up the directory, populate it with files needed for the flow. | 
|  | 42 | You need a project source file, a file to help with configuration, | 
|  | 43 | and a file to help create the Makefile, and a README file: | 
|  | 44 | ``hello.c``, ``configure.ac``, ``Makefile.am``, and ``README``, | 
|  | 45 | respectively. | 
|  | 46 |  | 
|  | 47 | Use the following command to create an empty README file, which is | 
| Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 48 | required by GNU Coding Standards:: | 
| Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 49 |  | 
|  | 50 | $ touch README | 
|  | 51 |  | 
|  | 52 | Create the remaining | 
|  | 53 | three files as follows: | 
|  | 54 |  | 
| Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 55 | -  ``hello.c``:: | 
| Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 56 |  | 
|  | 57 | #include <stdio.h> | 
|  | 58 |  | 
|  | 59 | main() | 
|  | 60 | { | 
|  | 61 | printf("Hello World!\n"); | 
|  | 62 | } | 
|  | 63 |  | 
| Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 64 | -  ``configure.ac``:: | 
| Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 65 |  | 
|  | 66 | AC_INIT(hello,0.1) | 
|  | 67 | AM_INIT_AUTOMAKE([foreign]) | 
|  | 68 | AC_PROG_CC | 
|  | 69 | AC_CONFIG_FILES(Makefile) | 
|  | 70 | AC_OUTPUT | 
|  | 71 |  | 
| Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 72 | -  ``Makefile.am``:: | 
| Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 73 |  | 
|  | 74 | bin_PROGRAMS = hello | 
|  | 75 | hello_SOURCES = hello.c | 
|  | 76 |  | 
|  | 77 | 2. *Source the Cross-Toolchain Environment Setup File:* As described | 
|  | 78 | earlier in the manual, installing the cross-toolchain creates a | 
|  | 79 | cross-toolchain environment setup script in the directory that the | 
|  | 80 | SDK was installed. Before you can use the tools to develop your | 
|  | 81 | project, you must source this setup script. The script begins with | 
|  | 82 | the string "environment-setup" and contains the machine architecture, | 
|  | 83 | which is followed by the string "poky-linux". For this example, the | 
|  | 84 | command sources a script from the default SDK installation directory | 
| Andrew Geissler | 09209ee | 2020-12-13 08:44:15 -0600 | [diff] [blame] | 85 | that uses the 32-bit Intel x86 Architecture and the &DISTRO; Yocto | 
| Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 86 | Project release:: | 
| Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 87 |  | 
| Andrew Geissler | 09209ee | 2020-12-13 08:44:15 -0600 | [diff] [blame] | 88 | $ source /opt/poky/&DISTRO;/environment-setup-i586-poky-linux | 
| Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 89 |  | 
|  | 90 | 3. *Create the configure Script:* Use the ``autoreconf`` command to | 
|  | 91 | generate the ``configure`` script. | 
|  | 92 | :: | 
|  | 93 |  | 
|  | 94 | $ autoreconf | 
|  | 95 |  | 
|  | 96 | The ``autoreconf`` | 
|  | 97 | tool takes care of running the other Autotools such as ``aclocal``, | 
|  | 98 | ``autoconf``, and ``automake``. | 
|  | 99 |  | 
|  | 100 | .. note:: | 
|  | 101 |  | 
| Andrew Geissler | 3b8a17c | 2021-04-15 15:55:55 -0500 | [diff] [blame] | 102 | If you get errors from ``configure.ac``, which ``autoreconf`` | 
| Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 103 | runs, that indicate missing files, you can use the "-i" option, | 
|  | 104 | which ensures missing auxiliary files are copied to the build | 
|  | 105 | host. | 
|  | 106 |  | 
|  | 107 | 4. *Cross-Compile the Project:* This command compiles the project using | 
|  | 108 | the cross-compiler. The | 
|  | 109 | :term:`CONFIGURE_FLAGS` | 
|  | 110 | environment variable provides the minimal arguments for GNU | 
| Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 111 | configure:: | 
| Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 112 |  | 
|  | 113 | $ ./configure ${CONFIGURE_FLAGS} | 
|  | 114 |  | 
|  | 115 | For an Autotools-based | 
|  | 116 | project, you can use the cross-toolchain by just passing the | 
|  | 117 | appropriate host option to ``configure.sh``. The host option you use | 
|  | 118 | is derived from the name of the environment setup script found in the | 
|  | 119 | directory in which you installed the cross-toolchain. For example, | 
|  | 120 | the host option for an ARM-based target that uses the GNU EABI is | 
|  | 121 | ``armv5te-poky-linux-gnueabi``. You will notice that the name of the | 
|  | 122 | script is ``environment-setup-armv5te-poky-linux-gnueabi``. Thus, the | 
|  | 123 | following command works to update your project and rebuild it using | 
| Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 124 | the appropriate cross-toolchain tools:: | 
| Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 125 |  | 
|  | 126 | $ ./configure --host=armv5te-poky-linux-gnueabi --with-libtool-sysroot=sysroot_dir | 
|  | 127 |  | 
|  | 128 | 5. *Make and Install the Project:* These two commands generate and | 
| Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 129 | install the project into the destination directory:: | 
| Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 130 |  | 
|  | 131 | $ make | 
|  | 132 | $ make install DESTDIR=./tmp | 
|  | 133 |  | 
|  | 134 | .. note:: | 
|  | 135 |  | 
|  | 136 | To learn about environment variables established when you run the | 
|  | 137 | cross-toolchain environment setup script and how they are used or | 
|  | 138 | overridden when the Makefile, see the " | 
|  | 139 | Makefile-Based Projects | 
|  | 140 | " section. | 
|  | 141 |  | 
|  | 142 | This next command is a simple way to verify the installation of your | 
|  | 143 | project. Running the command prints the architecture on which the | 
|  | 144 | binary file can run. This architecture should be the same | 
|  | 145 | architecture that the installed cross-toolchain supports. | 
|  | 146 | :: | 
|  | 147 |  | 
|  | 148 | $ file ./tmp/usr/local/bin/hello | 
|  | 149 |  | 
|  | 150 | 6. *Execute Your Project:* To execute the project, you would need to run | 
|  | 151 | it on your target hardware. If your target hardware happens to be | 
| Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 152 | your build host, you could run the project as follows:: | 
| Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 153 |  | 
|  | 154 | $ ./tmp/usr/local/bin/hello | 
|  | 155 |  | 
|  | 156 | As expected, the project displays the "Hello World!" message. | 
|  | 157 |  | 
|  | 158 | Makefile-Based Projects | 
|  | 159 | ======================= | 
|  | 160 |  | 
|  | 161 | Simple Makefile-based projects use and interact with the cross-toolchain | 
|  | 162 | environment variables established when you run the cross-toolchain | 
|  | 163 | environment setup script. The environment variables are subject to | 
|  | 164 | general ``make`` rules. | 
|  | 165 |  | 
|  | 166 | This section presents a simple Makefile development flow and provides an | 
|  | 167 | example that lets you see how you can use cross-toolchain environment | 
|  | 168 | variables and Makefile variables during development. | 
|  | 169 |  | 
|  | 170 | .. image:: figures/sdk-makefile-flow.png | 
|  | 171 | :align: center | 
|  | 172 |  | 
|  | 173 | The main point of this section is to explain the following three cases | 
|  | 174 | regarding variable behavior: | 
|  | 175 |  | 
|  | 176 | -  *Case 1 - No Variables Set in the Makefile Map to Equivalent | 
|  | 177 | Environment Variables Set in the SDK Setup Script:* Because matching | 
|  | 178 | variables are not specifically set in the ``Makefile``, the variables | 
|  | 179 | retain their values based on the environment setup script. | 
|  | 180 |  | 
|  | 181 | -  *Case 2 - Variables Are Set in the Makefile that Map to Equivalent | 
|  | 182 | Environment Variables from the SDK Setup Script:* Specifically | 
|  | 183 | setting matching variables in the ``Makefile`` during the build | 
|  | 184 | results in the environment settings of the variables being | 
|  | 185 | overwritten. In this case, the variables you set in the ``Makefile`` | 
|  | 186 | are used. | 
|  | 187 |  | 
|  | 188 | -  *Case 3 - Variables Are Set Using the Command Line that Map to | 
|  | 189 | Equivalent Environment Variables from the SDK Setup Script:* | 
|  | 190 | Executing the ``Makefile`` from the command line results in the | 
|  | 191 | environment variables being overwritten. In this case, the | 
|  | 192 | command-line content is used. | 
|  | 193 |  | 
|  | 194 | .. note:: | 
|  | 195 |  | 
|  | 196 | Regardless of how you set your variables, if you use the "-e" option | 
| Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 197 | with ``make``, the variables from the SDK setup script take precedence:: | 
| Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 198 |  | 
|  | 199 | $ make -e target | 
|  | 200 |  | 
|  | 201 |  | 
|  | 202 | The remainder of this section presents a simple Makefile example that | 
|  | 203 | demonstrates these variable behaviors. | 
|  | 204 |  | 
|  | 205 | In a new shell environment variables are not established for the SDK | 
|  | 206 | until you run the setup script. For example, the following commands show | 
|  | 207 | a null value for the compiler variable (i.e. | 
|  | 208 | :term:`CC`). | 
|  | 209 | :: | 
|  | 210 |  | 
|  | 211 | $ echo ${CC} | 
|  | 212 |  | 
|  | 213 | $ | 
|  | 214 |  | 
|  | 215 | Running the | 
|  | 216 | SDK setup script for a 64-bit build host and an i586-tuned target | 
| Andrew Geissler | 09209ee | 2020-12-13 08:44:15 -0600 | [diff] [blame] | 217 | architecture for a ``core-image-sato`` image using the current &DISTRO; | 
| Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 218 | Yocto Project release and then echoing that variable shows the value | 
| Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 219 | established through the script:: | 
| Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 220 |  | 
| Andrew Geissler | 09209ee | 2020-12-13 08:44:15 -0600 | [diff] [blame] | 221 | $ source /opt/poky/&DISTRO;/environment-setup-i586-poky-linux | 
| Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 222 | $ echo ${CC} | 
| Andrew Geissler | 09209ee | 2020-12-13 08:44:15 -0600 | [diff] [blame] | 223 | i586-poky-linux-gcc -m32 -march=i586 --sysroot=/opt/poky/&DISTRO;/sysroots/i586-poky-linux | 
| Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 224 |  | 
|  | 225 | To illustrate variable use, work through this simple "Hello World!" | 
|  | 226 | example: | 
|  | 227 |  | 
|  | 228 | 1. *Create a Working Directory and Populate It:* Create a clean | 
|  | 229 | directory for your project and then make that directory your working | 
|  | 230 | location. | 
|  | 231 | :: | 
|  | 232 |  | 
|  | 233 | $ mkdir $HOME/helloworld | 
|  | 234 | $ cd $HOME/helloworld | 
|  | 235 |  | 
|  | 236 | After | 
|  | 237 | setting up the directory, populate it with files needed for the flow. | 
|  | 238 | You need a ``main.c`` file from which you call your function, a | 
|  | 239 | ``module.h`` file to contain headers, and a ``module.c`` that defines | 
|  | 240 | your function. | 
|  | 241 |  | 
|  | 242 | Create the three files as follows: | 
|  | 243 |  | 
| Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 244 | -  ``main.c``:: | 
| Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 245 |  | 
|  | 246 | #include "module.h" | 
|  | 247 | void sample_func(); | 
|  | 248 | int main() | 
|  | 249 | { | 
|  | 250 | sample_func(); | 
|  | 251 | return 0; | 
|  | 252 | } | 
|  | 253 |  | 
| Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 254 | -  ``module.h``:: | 
| Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 255 |  | 
|  | 256 | #include <stdio.h> | 
|  | 257 | void sample_func(); | 
|  | 258 |  | 
| Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 259 | -  ``module.c``:: | 
| Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 260 |  | 
|  | 261 | #include "module.h" | 
|  | 262 | void sample_func() | 
|  | 263 | { | 
|  | 264 | printf("Hello World!"); | 
|  | 265 | printf("\n"); | 
|  | 266 | } | 
|  | 267 |  | 
|  | 268 | 2. *Source the Cross-Toolchain Environment Setup File:* As described | 
|  | 269 | earlier in the manual, installing the cross-toolchain creates a | 
|  | 270 | cross-toolchain environment setup script in the directory that the | 
|  | 271 | SDK was installed. Before you can use the tools to develop your | 
|  | 272 | project, you must source this setup script. The script begins with | 
|  | 273 | the string "environment-setup" and contains the machine architecture, | 
|  | 274 | which is followed by the string "poky-linux". For this example, the | 
|  | 275 | command sources a script from the default SDK installation directory | 
| Andrew Geissler | d1e8949 | 2021-02-12 15:35:20 -0600 | [diff] [blame] | 276 | that uses the 32-bit Intel x86 Architecture and the &DISTRO_NAME; Yocto | 
| Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 277 | Project release:: | 
| Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 278 |  | 
| Andrew Geissler | d1e8949 | 2021-02-12 15:35:20 -0600 | [diff] [blame] | 279 | $ source /opt/poky/&DISTRO;/environment-setup-i586-poky-linux | 
| Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 280 |  | 
|  | 281 | 3. *Create the Makefile:* For this example, the Makefile contains | 
|  | 282 | two lines that can be used to set the ``CC`` variable. One line is | 
|  | 283 | identical to the value that is set when you run the SDK environment | 
|  | 284 | setup script, and the other line sets ``CC`` to "gcc", the default | 
| Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 285 | GNU compiler on the build host:: | 
| Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 286 |  | 
|  | 287 | # CC=i586-poky-linux-gcc -m32 -march=i586 --sysroot=/opt/poky/2.5/sysroots/i586-poky-linux | 
|  | 288 | # CC="gcc" | 
|  | 289 | all: main.o module.o | 
|  | 290 | ${CC} main.o module.o -o target_bin | 
|  | 291 | main.o: main.c module.h | 
|  | 292 | ${CC} -I . -c main.c | 
|  | 293 | module.o: module.c | 
|  | 294 | module.h ${CC} -I . -c module.c | 
|  | 295 | clean: | 
|  | 296 | rm -rf *.o | 
|  | 297 | rm target_bin | 
|  | 298 |  | 
|  | 299 | 4. *Make the Project:* Use the ``make`` command to create the binary | 
|  | 300 | output file. Because variables are commented out in the Makefile, the | 
|  | 301 | value used for ``CC`` is the value set when the SDK environment setup | 
| Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 302 | file was run:: | 
| Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 303 |  | 
|  | 304 | $ make | 
|  | 305 | i586-poky-linux-gcc -m32 -march=i586 --sysroot=/opt/poky/2.5/sysroots/i586-poky-linux -I . -c main.c | 
|  | 306 | i586-poky-linux-gcc -m32 -march=i586 --sysroot=/opt/poky/2.5/sysroots/i586-poky-linux -I . -c module.c | 
|  | 307 | i586-poky-linux-gcc -m32 -march=i586 --sysroot=/opt/poky/2.5/sysroots/i586-poky-linux main.o module.o -o target_bin | 
|  | 308 |  | 
|  | 309 | From the results of the previous command, you can see that | 
|  | 310 | the compiler used was the compiler established through the ``CC`` | 
|  | 311 | variable defined in the setup script. | 
|  | 312 |  | 
|  | 313 | You can override the ``CC`` environment variable with the same | 
|  | 314 | variable as set from the Makefile by uncommenting the line in the | 
|  | 315 | Makefile and running ``make`` again. | 
|  | 316 | :: | 
|  | 317 |  | 
|  | 318 | $ make clean | 
|  | 319 | rm -rf *.o | 
|  | 320 | rm target_bin | 
|  | 321 | # | 
|  | 322 | # Edit the Makefile by uncommenting the line that sets CC to "gcc" | 
|  | 323 | # | 
|  | 324 | $ make | 
|  | 325 | gcc -I . -c main.c | 
|  | 326 | gcc -I . -c module.c | 
|  | 327 | gcc main.o module.o -o target_bin | 
|  | 328 |  | 
|  | 329 | As shown in the previous example, the | 
|  | 330 | cross-toolchain compiler is not used. Rather, the default compiler is | 
|  | 331 | used. | 
|  | 332 |  | 
|  | 333 | This next case shows how to override a variable by providing the | 
|  | 334 | variable as part of the command line. Go into the Makefile and | 
|  | 335 | re-insert the comment character so that running ``make`` uses the | 
|  | 336 | established SDK compiler. However, when you run ``make``, use a | 
| Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 337 | command-line argument to set ``CC`` to "gcc":: | 
| Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 338 |  | 
|  | 339 | $ make clean | 
|  | 340 | rm -rf *.o | 
|  | 341 | rm target_bin | 
|  | 342 | # | 
|  | 343 | # Edit the Makefile to comment out the line setting CC to "gcc" | 
|  | 344 | # | 
|  | 345 | $ make | 
|  | 346 | i586-poky-linux-gcc  -m32 -march=i586 --sysroot=/opt/poky/2.5/sysroots/i586-poky-linux -I . -c main.c | 
|  | 347 | i586-poky-linux-gcc  -m32 -march=i586 --sysroot=/opt/poky/2.5/sysroots/i586-poky-linux -I . -c module.c | 
|  | 348 | i586-poky-linux-gcc  -m32 -march=i586 --sysroot=/opt/poky/2.5/sysroots/i586-poky-linux main.o module.o -o target_bin | 
|  | 349 | $ make clean | 
|  | 350 | rm -rf *.o | 
|  | 351 | rm target_bin | 
|  | 352 | $ make CC="gcc" | 
|  | 353 | gcc -I . -c main.c | 
|  | 354 | gcc -I . -c module.c | 
|  | 355 | gcc main.o module.o -o target_bin | 
|  | 356 |  | 
|  | 357 | In the previous case, the command-line argument overrides the SDK | 
|  | 358 | environment variable. | 
|  | 359 |  | 
|  | 360 | In this last case, edit Makefile again to use the "gcc" compiler but | 
| Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 361 | then use the "-e" option on the ``make`` command line:: | 
| Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 362 |  | 
|  | 363 | $ make clean | 
|  | 364 | rm -rf *.o | 
|  | 365 | rm target_bin | 
|  | 366 | # | 
|  | 367 | # Edit the Makefile to use "gcc" | 
|  | 368 | # | 
|  | 369 | $ make | 
|  | 370 | gcc -I . -c main.c | 
|  | 371 | gcc -I . -c module.c | 
|  | 372 | gcc main.o module.o -o target_bin | 
|  | 373 | $ make clean | 
|  | 374 | rm -rf *.o | 
|  | 375 | rm target_bin | 
|  | 376 | $ make -e | 
|  | 377 | i586-poky-linux-gcc  -m32 -march=i586 --sysroot=/opt/poky/2.5/sysroots/i586-poky-linux -I . -c main.c | 
|  | 378 | i586-poky-linux-gcc  -m32 -march=i586 --sysroot=/opt/poky/2.5/sysroots/i586-poky-linux -I . -c module.c | 
|  | 379 | i586-poky-linux-gcc  -m32 -march=i586 --sysroot=/opt/poky/2.5/sysroots/i586-poky-linux main.o module.o -o target_bin | 
|  | 380 |  | 
|  | 381 | In the previous case, the "-e" option forces ``make`` to | 
|  | 382 | use the SDK environment variables regardless of the values in the | 
|  | 383 | Makefile. | 
|  | 384 |  | 
|  | 385 | 5. *Execute Your Project:* To execute the project (i.e. ``target_bin``), | 
| Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 386 | use the following command:: | 
| Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 387 |  | 
|  | 388 | $ ./target_bin | 
|  | 389 | Hello World! | 
|  | 390 |  | 
|  | 391 | .. note:: | 
|  | 392 |  | 
|  | 393 | If you used the cross-toolchain compiler to build | 
|  | 394 | target_bin | 
|  | 395 | and your build host differs in architecture from that of the | 
|  | 396 | target machine, you need to run your project on the target device. | 
|  | 397 |  | 
|  | 398 | As expected, the project displays the "Hello World!" message. |