Difference between revisions of "Using EMAC OE SDK Example Projects"
(Created page with "The EMAC OE SDK is distributed with a set of example projects intended to demonstrate how to use the EMAC OE toolchain and libraries. This guide demonstrates the process of co...") |
|||
(10 intermediate revisions by 5 users not shown) | |||
Line 1: | Line 1: | ||
− | + | {{todo|SEOKWREV (11.26.13-22:36->MG+);(12.17.13-00:10->MD+);(12.17.13-11:20->KY+);(03.04.14-16:20->BS-);(03.19.14-16:50->BS+);(04.14.14-14:35->BS+)|Michael Gloff|project=oe 4,mg,ky,SEOKWREV,md,bs}} | |
− | This guide | + | {{#seo: |
+ | |title=Using EMAC OE SDK Example Projects | ||
+ | |titlemode=append | ||
+ | |keywords=EMAC Hello Project,EMAC Example Makefile,EMAC Example C File | ||
+ | |description=Using EMAC OE SDK example projects. | ||
+ | }} | ||
+ | The EMAC OE SDK is distributed with a set of example projects intended to demonstrate how to use the EMAC OE toolchain and libraries. This guide demonstrates the process of compiling one of the example projects and running it on the target machine. It is assumed that the procedure in the [[ Configuring_EMAC_OE_4.0_SDK | EMAC OE SDK Configuration Guide]] has been followed prior to reading this page. | ||
− | + | This guide consists of a simple hello.c source file and a Makefile build file located within Listing 2 and Listing 3, respectively. | |
− | + | ||
− | + | <br clear=all> | |
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
==Tools== | ==Tools== | ||
Line 18: | Line 17: | ||
* GNU <code>make</code>. Manages project dependencies. | * GNU <code>make</code>. Manages project dependencies. | ||
* EMAC OE SDK. [See the EMAC OE SDK Install Page]. | * EMAC OE SDK. [See the EMAC OE SDK Install Page]. | ||
− | * <code>wput</code>, Provides FTP capability | + | * <code>wput</code>, Provides file transfer (FTP) capability. |
+ | |||
==EMAC SDK Example: Compile the "hello" Project== | ==EMAC SDK Example: Compile the "hello" Project== | ||
− | This procedure provides an overview of how to compile and run C applications for EMAC products. It assumes familiarity with the C programming language and is intended to be used by experienced programmers | + | This procedure provides an overview of how to compile and run C applications for EMAC products. It assumes familiarity with the C programming language and is intended to be used by experienced programmers. The “hello” example project source can be found in the projects/ subdirectory of the EMAC OE SDK root directory. The full path to the source is as follows: |
<syntaxhighlight lang="console"> | <syntaxhighlight lang="console"> | ||
Line 28: | Line 28: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
− | Cross-compile the program using GNU Make. | + | |
+ | Cross-compile the program using GNU Make. From the terminal prompt type: | ||
<syntaxhighlight lang="bash"> | <syntaxhighlight lang="bash"> | ||
Line 35: | Line 36: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
− | <code>all</code> is a make target. This command is the equivalent to the | + | The file <code>Makefile</code> specifies what Make targets are available and what actions should be performed for each target. <code>all</code> is a make target that directs Make to compile all source files for the project. This command is the equivalent to the Build All command found in most IDE's. The build system will only compile files which have been modified since the last build. |
− | + | ||
+ | The Makefile based build system fully supports incremental builds. If a full rebuild is required, issue the following two commands. | ||
<syntaxhighlight lang="bash"> | <syntaxhighlight lang="bash"> | ||
+ | developer@ldc:~$ make clean | ||
developer@ldc:~$ make | developer@ldc:~$ make | ||
</syntaxhighlight> | </syntaxhighlight> | ||
− | |||
− | The | + | The <code>make clean</code> command will delete any object files (with the <code>.o</code> extension), debugger information files (with the <code>.gdb</code> extension), executable binaries (generally, no extension) and any other files which are generated during the build process. Once this cleaning step is complete, the build system will attempt to rebuild everything. |
− | + | For a more in-depth explanation on the gcc build process, see the [http://www.gnu.org/software/make/manual/make.html GNU "make" Manual]. | |
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
==EMAC SDK Example: Uploading and Running the "hello" Project"== | ==EMAC SDK Example: Uploading and Running the "hello" Project"== | ||
Line 63: | Line 59: | ||
developer@ldc:~$ make upload | developer@ldc:~$ make upload | ||
</syntaxhighlight> | </syntaxhighlight> | ||
+ | |||
<code>upload</code> is another make target. This command will send your freshly compiled binary to the target machine. | <code>upload</code> is another make target. This command will send your freshly compiled binary to the target machine. | ||
− | This | + | This <code>Make</code> target uses the development system's <code>wput</code> program to send the binary to the target machine through FTP. This is accomplished using the TARGET_IP, LOGIN, and PASSWORD variables stored in the <code>global.properties</code> file. The <code>global.properties</code> file also contains variables which <code>Make</code> passes to the compiler to ensure that the executable produced is compatible with the target CPU architecture. |
===Running the Program on the Target Machine=== | ===Running the Program on the Target Machine=== | ||
− | Connect remotely to the target machine | + | Connect remotely to the target machine using SSH and run the program as shown below. |
<syntaxhighlight lang="bash"> | <syntaxhighlight lang="bash"> | ||
+ | developer@ldc:~$ ssh root@TARGET_IP | ||
+ | ... | ||
root@emac-oe:~# chmod u+x /tmp/hello | root@emac-oe:~# chmod u+x /tmp/hello | ||
root@emac-oe:~# /tmp/hello | root@emac-oe:~# /tmp/hello | ||
</syntaxhighlight> | </syntaxhighlight> | ||
+ | |||
'''Listing 1. Running the Remote Application''' | '''Listing 1. Running the Remote Application''' | ||
− | + | * <code>chmod u+x</code> sets the root user's permissions to allow execution of the binary. | |
+ | * <code>/tmp/hello</code> runs the program without any arguments. | ||
− | |||
− | {{mbox | type = notice | text = '''NOTE:''' | + | {{mbox | type = notice | text = '''NOTE:''' In order to run a program located in the current working directory, it must be run as <code>./hello</code>. The shell will only look for a program in the default search <code>PATH</code>, unless the program's name is prefixed with a complete path to it's location.}} |
− | |||
− | If the file compiles without trouble but has runtime bugs, you can remotely debug the application using gdbserver. Read the [[EMAC OE SDK Remote Debugging Guide]] to learn more. | + | If the file compiles without trouble but has runtime bugs, you can remotely debug the application using gdbserver. Read the [[ Remote_Debugging_EMAC_OE_SDK_Projects_with_gdbserver | EMAC OE SDK Remote Debugging Guide]] to learn more. |
===Example C File=== | ===Example C File=== | ||
Line 151: | Line 150: | ||
-include $(DEPS) | -include $(DEPS) | ||
</syntaxhighlight> | </syntaxhighlight> | ||
+ | |||
'''Listing 3. Example EMAC OE SDK Makefile''' | '''Listing 3. Example EMAC OE SDK Makefile''' | ||
− | + | '''NOTE:''' Using the documentation for GNU <code>make</code> will be required to gain a solid understanding of the build system. Following is a brief description of this Makefile. | |
− | * The <code>include</code> command tells <code>make</code> to | + | * The <code>include</code> command tells <code>make</code> to also look at the file specified for variable definitions. |
− | * The <code>TARGET=</code> directive tells <code>make</code> the name and location it should use for any executable binaries or shared object binaries | + | * The <code>TARGET=</code> directive tells <code>make</code> the name and location it should use for any executable binaries or shared object binaries it produces. |
* The <code>CFILES=</code> directive tells <code>make</code> the names of the C source files it needs to build. | * The <code>CFILES=</code> directive tells <code>make</code> the names of the C source files it needs to build. | ||
* The <code>OBJS=</code> and <code>DEPS=</code> directives tell <code>make</code> how to produce file names for the object and dependency files it generates. This file specifies a method for these which will work for most projects, and is unlikely to need modification. | * The <code>OBJS=</code> and <code>DEPS=</code> directives tell <code>make</code> how to produce file names for the object and dependency files it generates. This file specifies a method for these which will work for most projects, and is unlikely to need modification. | ||
* <code>all:</code> specifies the make target named “all.” <code>clean:</code> and <code>upload:</code>, similarly, specify the make targets for targets of these names, respectively. New make targets can be given names this way. make will perform all the steps listed after the target name until it encounters another target name. | * <code>all:</code> specifies the make target named “all.” <code>clean:</code> and <code>upload:</code>, similarly, specify the make targets for targets of these names, respectively. New make targets can be given names this way. make will perform all the steps listed after the target name until it encounters another target name. | ||
− | * The <code>CC</code> variable refers to the <code>gcc</code> command | + | * The <code>CC</code> variable refers to the <code>gcc</code> command defined in the <code>global.properties</code> file. The <code>$(CC)</code> syntax tells <code>make</code> to read the value of the variable, <code>CC</code>, and replace <code>$(CC)</code> with the value of <code>CC</code> prior to attempting to execute the command. |
+ | |||
+ | |||
+ | {{mbox | type = notice | text = '''NOTE:''' This is a basic Makefile which can be extended as needed to support many projects. More complex projects may require the use of a ''build system builder'' tool to help generate scripts that can be used to build a project. Options include: | ||
+ | * Learning the <code>make</code> system thoroughly. | ||
+ | * Adopt a build system builder tool such as''CMake''. ''CMake'' is a simple yet powerful tool for dealing with large projects. | ||
+ | * The Eclipse IDE contains a build system builder that may be able to handle the complex requirements of the project.}} | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
==Next Steps== | ==Next Steps== | ||
− | After compiling and running an example project, the next step is to create a new project. The [[EMAC OE SDK New Project Guide]] details this process from start to finish. | + | After compiling and running an example project, the next step is to create a new project from scratch. The [[Creating_a_New_EMAC_OE_SDK_Project | EMAC OE SDK New Project Guide]] details this process from start to finish. |
− | + | <!--[[Category:EMAC OE SDK]]--> | |
− | |||
− | |||
− | |||
− | |||
− | |||
− |
Latest revision as of 13:34, 14 April 2014
The EMAC OE SDK is distributed with a set of example projects intended to demonstrate how to use the EMAC OE toolchain and libraries. This guide demonstrates the process of compiling one of the example projects and running it on the target machine. It is assumed that the procedure in the EMAC OE SDK Configuration Guide has been followed prior to reading this page.
This guide consists of a simple hello.c source file and a Makefile build file located within Listing 2 and Listing 3, respectively.
Contents
Tools
- GNU
make
. Manages project dependencies. - EMAC OE SDK. [See the EMAC OE SDK Install Page].
wput
, Provides file transfer (FTP) capability.
EMAC SDK Example: Compile the "hello" Project
This procedure provides an overview of how to compile and run C applications for EMAC products. It assumes familiarity with the C programming language and is intended to be used by experienced programmers. The “hello” example project source can be found in the projects/ subdirectory of the EMAC OE SDK root directory. The full path to the source is as follows:
/path/to/sdk/EMAC-OE-arm-linux-gnueabi-SDK_XX.YY/projects/hello/
Cross-compile the program using GNU Make. From the terminal prompt type:
developer@ldc:~$ cd /path/to/sdk/EMAC-OE-arm-linux-gnueabi-SDK_XX.YY/projects/hello/
developer@ldc:~$ make all
The file Makefile
specifies what Make targets are available and what actions should be performed for each target. all
is a make target that directs Make to compile all source files for the project. This command is the equivalent to the Build All command found in most IDE's. The build system will only compile files which have been modified since the last build.
The Makefile based build system fully supports incremental builds. If a full rebuild is required, issue the following two commands.
developer@ldc:~$ make clean
developer@ldc:~$ make
The make clean
command will delete any object files (with the .o
extension), debugger information files (with the .gdb
extension), executable binaries (generally, no extension) and any other files which are generated during the build process. Once this cleaning step is complete, the build system will attempt to rebuild everything.
For a more in-depth explanation on the gcc build process, see the GNU "make" Manual.
EMAC SDK Example: Uploading and Running the "hello" Project"
Uploading the Program to the Target Machine
developer@ldc:~$ make upload
upload
is another make target. This command will send your freshly compiled binary to the target machine.
This Make
target uses the development system's wput
program to send the binary to the target machine through FTP. This is accomplished using the TARGET_IP, LOGIN, and PASSWORD variables stored in the global.properties
file. The global.properties
file also contains variables which Make
passes to the compiler to ensure that the executable produced is compatible with the target CPU architecture.
Running the Program on the Target Machine
Connect remotely to the target machine using SSH and run the program as shown below.
developer@ldc:~$ ssh root@TARGET_IP
...
root@emac-oe:~# chmod u+x /tmp/hello
root@emac-oe:~# /tmp/hello
Listing 1. Running the Remote Application
chmod u+x
sets the root user's permissions to allow execution of the binary./tmp/hello
runs the program without any arguments.
NOTE: In order to run a program located in the current working directory, it must be run as ./hello . The shell will only look for a program in the default search PATH , unless the program's name is prefixed with a complete path to it's location. |
If the file compiles without trouble but has runtime bugs, you can remotely debug the application using gdbserver. Read the EMAC OE SDK Remote Debugging Guide to learn more.
Example C File
This C file can be used by programmers as an example to ensure their build configuration for EMAC products is functioning correctly.
/**
* @file hello.c
*
* Simple Hello World application for EMAC OE.
*
* @author EMAC, Inc. <support@emacinc.com>
*/
/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
#include <stdio.h>
#include <stdlib.h>
int main(void)
{
printf("Hello EMAC OE!\n");
exit(EXIT_SUCCESS);
}
Listing 2. "Hello World" example project
Example Makefile
Listing 3 shows the default Makefile
used for the hello example project. This is a necessary component of the EMAC SDK which directs GNU Make in resolving source code dependencies before calling the cross-compiler to create a binary for the target platform. It also provides a convenient upload target which utilizes the development system's wput
command to send the compiled binary to the target system.
include ../global.properties
TARGET=hello
CFILES=hello.c
OBJS=$(CFILES:.c=.o)
DEPS=$(OBJS:.o=.d)
all: $(TARGET)
$(TARGET): $(OBJS) Makefile
$(CC) $(VERBOSE) $(OBJS) $(OFLAGS) $(LIBFLAGS) $(SLIBS) -o $@
%.o: %.c
$(CC) $(VERBOSE) $(CFLAGS) -o $@ -c $<
clean:
$(RM) *.o *.gdb $(TARGET) $(DEPS)
upload: all
$(WPUT) $(TARGET) ftp://$(LOGIN):$(PASSWORD)@$(TARGET_IP)/../../tmp/$(TARGET)
-include $(DEPS)
Listing 3. Example EMAC OE SDK Makefile
NOTE: Using the documentation for GNU make
will be required to gain a solid understanding of the build system. Following is a brief description of this Makefile.
- The
include
command tellsmake
to also look at the file specified for variable definitions. - The
TARGET=
directive tellsmake
the name and location it should use for any executable binaries or shared object binaries it produces. - The
CFILES=
directive tellsmake
the names of the C source files it needs to build. - The
OBJS=
andDEPS=
directives tellmake
how to produce file names for the object and dependency files it generates. This file specifies a method for these which will work for most projects, and is unlikely to need modification. all:
specifies the make target named “all.”clean:
andupload:
, similarly, specify the make targets for targets of these names, respectively. New make targets can be given names this way. make will perform all the steps listed after the target name until it encounters another target name.- The
CC
variable refers to thegcc
command defined in theglobal.properties
file. The$(CC)
syntax tellsmake
to read the value of the variable,CC
, and replace$(CC)
with the value ofCC
prior to attempting to execute the command.
NOTE: This is a basic Makefile which can be extended as needed to support many projects. More complex projects may require the use of a build system builder tool to help generate scripts that can be used to build a project. Options include:
|
Next Steps
After compiling and running an example project, the next step is to create a new project from scratch. The EMAC OE SDK New Project Guide details this process from start to finish.