Using the EMAC OE SDK Projects with Eclipse

From wiki.emacinc.com
Revision as of 22:37, 29 October 2013 by Mdean (talk | contribs) (Fixed error.)
Jump to: navigation, search
TODO: {{#todo:Review|Klint Youngmeyer|oe 4,oe 5,ky,review, md}}


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 using the Eclipse IDE. A basic familiarity with Eclipse is assumed for this guide. For a quick intro, see the First Time Starting EMAC Eclipse.This guide uses the hello EMAC OE SDK example project. It consists of a C file and Makefile.

Tools Required

  • GNU make
  • EMAC OE SDK
  • wput



EMAC SDK Example: Compile and Run the hello Project

Setup

  1. Modify global.properties according to the SDK Remote Upload Setup to provide make with the correct user, password, and IP address for the upload target.
  2. Create a remote terminal connection. This is necessary to use the Remote System Explorer's SSH Terminal feature in the following procedure.

Building the Project

This procedure provides an overview of how to compile and run C applications for EMAC products in Eclipse. It assumes familiarity with the C programming language and is not intended as a general guide on learning to program.

  1. Click Window → Open Perspective → Other... To bring up a dialog window with a list of Perspectives to choose from.
  2. Choose C/C++ and click Ok.[1]

Building With the Eclipse Managed Build System

To build using Eclipse's managed build system, a project needs to be created from the Makefile-based project. To do this, perform the following steps:

  1. Select File→New→Makefile Project with Existing Code
  2. In the window that appears (as shown below), click the Browse... button.

Import Existing Code

Choosing the Project

  1. Navigate to the location of the project. By default, this is under your home directory in ~/EMAC-OE-arm-linux-gnueabi-SDK_4.0/projects/hello
  2. The files listed in the directory will be grayed out, but this is to be expected: Eclipse is just looking for the root directory of the project you are importing. Click the OK button.
  3. Your Import window should now look similar to this:

Import "Hello" Project

Click the Finish button.You should now see the following in your Project Explorer:

Project Explorer after importing "Hello" project.

The arrowhead to the left of hello indicates that the hello project is open. Click on the arrowhead to see the files in the project. Double click on the hello.c file to open it. Note: This step is not necessary for building the project. Notice the arrowhead which appeared next to hello.c. This indicates that the file is now open.

To build the project, ensure the project is highlighted in the Project Explorer treeview in the left pane, then select Project->Build Project. The project will now build, and your window should appear similar to the screenshot below:

Eclipse window after building the "Hello" example project.


If there are any build errors, they will be shown in the Console and/or Problems tabs on the bottom.

EMAC SDK with Qt Example: Compile and Run the textedit Project

Importing the Project

This procedure provides an overview of how to compile and run Qt C++ applications for EMAC products in Eclipse. It assumes familiarity with the C++ programming language and is not intended as a general guide on learning to program, learning C++, or learning Qt.

  1. Click Window → Open Perspective → Other... To bring up a dialog window with a list of Perspectives to choose from.
  2. Choose Qt C++ and click Ok.

Building With the Eclipse Managed Build System

To build using Eclipse's managed build system, the project needs to be imported using its .pro project file. To do this, perform the following steps:


  1. In the Project Explorer treeview control on the left side of the screen, make sure nothing is selected (click in a blank area, if necessary), put the mouse cursor in a blank area and right click. From the context menu which appears, select, Import...

    Importing a project into Eclipse

  2. In the window that appears (as shown below), make sure Qt Project is selected from the Qt entry in the treeview.

    Selecting Qt Project as the project type

  3. Click Next >, then click the Browse... button and navigate to the projects/qt_demos/textedit directory underneath the install location of your EMAC OE Qt SDK.

    Choosing the Qt project to import

  4. Highlight the .pro file, as shown above, and click OK.
  5. Click Finish.

Building the Project

You should now see the following in your Project Explorer:

Project Explorer after importing textedit project.

The arrowhead to the left of textedit indicates that the textedit project is open. Click on the arrowhead to see the files in the project. Double click on the textedit.cpp file to open it. (Note: This step is not necessary for building the project.) Notice the arrowhead which appears next to textedit.cpp. This can be used to see a list of classes and functions available within this source file.

To build the project, ensure the project is highlighted in the Project Explorer treeview in the left pane, then select Project→Run qmake. Now, select Project→Build Project. The project will now build, and your window should appear similar to the screenshot below:

Eclipse window after building the textedit example project.

If there are any build errors, they will be shown in the Console and/or Problems tabs on the bottom.

Building With Make Targets

  1. Select the Make Targets View.
  2. Expand EMAC-OE-arm-linux-gnueabi-SDK_4.0 → projects → hello.[2]
  3. Cross-compile the program:
    Click on the project you're building in the left pane to ensure it is highlighted in blue. The result is shown in Figure 1 below. Now click on Project→Build Project.

    Build Project

    The project to be built must be hilighted in the left pane, as shown above, before you click Project→Build Project to compile the hello example project (this is true any time you build a project). Build Project will perform an incremental build of the currently selected project. Choosing Project→Clean... before choosing Project→Build Project will perform a full rebuild of the project. The method used to determine what to build during an incremental build can be found here: GNU 'make' Manual.


Uploading the Project to the Target Machine

In order to use the make target for uploading the code to the target machine (your board from EMAC), you could run the following command in a shell:[3]

make upload

In fact, this is what Eclipse will execute for you in order to perform this step. In order to tell Eclipse how to do this, we first need to create a make target for the upload make target. To do so, perform the following steps:

  1. Right click on the project name in the left pane (hello in this example), and choose Make Targets→Build... (or just press <Shift>-<F9> while the project is highlighted in blue). This will bring up the window shown below:

    Make targets

  2. Check to see if there is an upload target in the list shown. If so, skip the next step.
  3. If there is no upload target, click the Add... button located in the upper right corner of the window shown in Figure 2. The window shown below will appear.

    Create make target

    Fill in the word upload for Target name, and Eclipse will automatically set upload to the name of the make target. Ensure the information in your Create Make Target corresponds to that shown above, and click Ok.
  4. To upload the executable to the target machine, click on the upload target in the Make Targets window as shown below.

    upload selected in Make Targets

    Once you have selected the upload target, click build. The binary executable should be uploaded to the target machine. If there is an error, check to ensure you have the wput command installed, and that it can be called from within the Eclipse IDE (to ensure the PATH used by Eclipse contains the directory where wput is located). See local to see how to get a shell within the Eclipse environment which can be used to check for the wput command by typing wput -h. If wput can be found within the PATH being used by Eclipse, you will see help information on how to use the command. Otherwise, wput is either not installed or not in the PATH.[4] Assuming wput is installed and can be found in the PATH, the Makefile will use variables stored in the global.properties file to call wput to upload the binary executable to the target machine. The global.properties file is included in the Makefile using the include keyword. This include statement is automatically placed into the Makefile by the Eclipse build system. 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.
  5. Now Connect to the target machine.
  6. Run the program as shown below using the remote terminal created in the Remote Terminal Setup Guide.

    Running the Remote Application

    The following is a brief description of each command seen in the SSH Terminal window above:
    1. cd /tmp: Change the current working directory to /tmp/.
    2. ls -l: List the current working directory's contents with file permissions shown. Notice that root does not have execute permissions for the file hello.
    3. chmod u+x hello: Give executable permissions to the owner of the hello file. Note that this assumes that the same user is used to log in through the SSH Terminal as was specified in global.properties according to Step 1 of the Setup for this guide--in this example, the user is root.
    4. ls -l: List the current working directory's contents with file permissions shown to be sure that root now has execute permission. The new x indicates that root does now have execute permissions.
    5. ./hello: Execute the binary. The output shown is a simple message printed to the screen, "Hello EMAC OE!".



If you want to make modifications to the Example C File and recompile it, follow the same procedure as above to test it again. With a few iterations of this the process will become familiar and easy.

Example C File

This C file can be used by programmers as an example to ensure their build system for EMAC products is functioning correctly. It is included in the EMAC OE SDK Example Project Guide.

Example Makefile

The EMAC OE SDK Example Project Guide shows the default Makefile file used for the hello example project. This is a necessary component of the EMAC OE 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. If you intend to write your own Makefile from scratch, EMAC recommends paying close attention to the include paths to learn more about the SDK cross compilation tools.

Next Steps

The next step is to create a new Makefile-based Eclipse project from scratch. This process is similar to the example above, but requires a few extra steps. See the New Project Guide for help on this.



  1. See Note 1
  2. See Note 2
  3. In Linux, a shell is similar to a Command Prompt on other operating systems
  4. See your Linux distribution's documentation to learn how to install the wput command (this is Ubuntu Linux if you're using the LDC).
    Information about the PATH environment variable can be found by typing man bash at a shell prompt, then typing /COMMAND EXECUTION (in all caps) to search for the relevant section of the Bash manpage.