Getting Started With C for Eclipse

download Getting Started With C for Eclipse

of 12

Transcript of Getting Started With C for Eclipse

  • 7/25/2019 Getting Started With C for Eclipse

    1/121/12 www.ni.c

    1.2.3.4.5.

    6.7.8.9.0.

    1.

    2.

    1.2.

    3.

    4.

    Getting Started with C/C++ Development Tools for NI Linux Real-Time, Eclipse Edition

    Publish Date: Apr 28, 2015

    Table of Contents

    OverviewInstallationConfiguring C/C++ Development Tools for NI Linux Real-Time, Eclipse Edition, for First UseCreating a C/C++ ProjectCreating a Build of a C/C++ Project

    Configuring a Remote SystemRunning a C/C++ Executable on Your NI Linux Real-Time TargetDebugging a C/C++ ProjectRelated InformationLegal Information

    Getting Started with C/C++ Development Tools for NI Linux Real-Time, Eclipse Edition

    1. Overview

    The Getting Started content is provided below, and it also installs with the product in the \\Eclipse\help

    page, or view the Getting Started content installed with the product.

    This tutorial outlines how to create C/C++ projects using C/C++ Development Tools for NI Linux Real-Time, Eclipse Edition, buildan executable from your project source code, and run and debug the executable on your NI Linux Real-Time target.

    2. Installation

    Install Java (Java SE 6 or greater is recommended), which you can download at http://www.java.com/getjava (.http://www.java.com/getjava)

    Install C/C++ Development Tools for NI Linux Real-Time, Eclipse Edition.

    3. Configuring C/C++ Development Tools for NI Linux Real-Time, Eclipse Edition, for First Use

    Complete the following steps to configure C/C++ Development Tools for NI Linux Real-Time, Eclipse Edition, for first use:

    Launch C/C++ Development Tools for NI Linux Real-Time, Eclipse Edition.When prompted, select a folder in which to store Eclipse projects and click .OK

    Tip Enable to save a project folder as your default workspace.Use this as the default and do not ask again

    In the Eclipse welcome screen, select the icon on the far right to open the workbench view.Workbench

    C/C++ Development Tools for NI Linux Real-Time, Eclipse Edition, highlights the active perspective on the perspectives bar, ashown in the following image. The first time you use C/C++ Development Tools for NI Linux Real-Time, Eclipse Edition, theworkbench view opens in the C/C++ perspective.

    http://www.java.com/getjavahttp://www.java.com/getjavahttp://www.java.com/getjavahttp://www.java.com/getjavahttp://www.java.com/getjavahttp://www.java.com/getjava
  • 7/25/2019 Getting Started With C for Eclipse

    2/122/12 www.ni.c

    1.2.3.4.5.6.

    7.

    8.9.

    In the next section of this tutorial, you create a new project in the C/C++ perspective.

    4. Creating a C/C++ Project

    Complete the following steps to create a C or C++ project in C/C++ Development Tools for NI Linux Real-Time, Eclipse Edition:

    Switch to the C/C++ perspective.Select to open the New Project Wizard.FileNewProjectExpand the folder and select or depending on the programming language you wish to use.C/C++ C Project C++ ProjectClick to open the page.Next C ProjectEnter a project name in the text box.Project nameSelect the under the folder in the listbox.Hello World ANSI Project Executable Project type

    Note This tutorial uses the Hello Word ANSI Project for instructional purposes. You can select any project type that fits youneeds.

    Select in the listbox to enable cross-compilation, which configures the compiler to create executableCross GCC Toolchainscode for embedded systems, such as your NI Linux Real-Time target.

    Click to open the page.Next Basic SettingsEnter the basic properties of your project in the , , , and text boxes.Author Copyright notice Hello world greeting Source

    Note The text box specifies the directory on your development computer hard drive used to store the projectSourcesource code.

  • 7/25/2019 Getting Started With C for Eclipse

    3/123/12 www.ni.c

    0.1.

    2.3.

    4.

    Click to open the page.Next Select ConfigurationsEnable to configure the project to allow debugging your executable, and/or enable to configure the project toDebug Releaseallow building a smaller, faster executable optimized for release.

    Note For purposes of this tutorial, ensure you enable .Debug

    Click to open the page.Next Cross GCC CommandIn the text box, enter one of the values from the following list, including the hyphen (-) at the end, toCross compiler prefixspecify the correct compiler for your NI Linux Real-Time target:

    (ARM-based targets, 2013 software stack)arm-none-linux-gnueabi-(ARM-based targets, 2014 software stack)arm-nilrt-linux-gnueabi-

    (Intel x64-based targets, 2014 software stack)x86_64-nilrt-linux-

    In the text box, browse to the location of the correct compiler for your target as specified in the followingCross compiler path

    list:

  • 7/25/2019 Getting Started With C for Eclipse

    4/124/12 www.ni.c

    5.

    1.2.

    (ARM-based targets, 2013 software stack)\\Eclipse\toolchain\gcc-4.4-arm\i386\bin

    (ARM-based targets, 2014 software stack)\\Eclipse\14.0\arm\sysroots\i686-nilrtsdk-mingw32\usr\bin\armv7a-vfp-neon-nilrt-lin

    (Intel x64-based targets, 2014 software stack)\\Eclipse\14.0\x64\sysroots\i686-nilrtsdk-mingw32\usr\bin\x86_64-nilrt-linux

    Click to create your project and return to the workbench view.Finish

    In the next section of this tutorial, you create an executable build of your project to enable it to run.

    5. Creating a Build of a C/C++ Project

    Before you can run your project, you need to test that your source code compiles by creating an executable build of your project.

    Complete the following steps to create an executable build of a C/C++ project:

    Switch to the C/C++ perspective.Modify the template source code if you want to adapt the template to your application needs, or enter C/C++ code if youselected a blank project. For purposes of this tutorial, you do not need to make changes to the Hello Word ANSI Project source

    code.

  • 7/25/2019 Getting Started With C for Eclipse

    5/125/12 www.ni.c

    3.

    4.5.

    6.1.2.3.

    7.8.

    Right-click your project in the tab and select .Project Explorer Properties

    Select in the left pane of the dialog box.C/C++ Build PropertiesSelect from the pull-down menu for the Debug configuration. Selecting the internal builder usesInternal builder Builder typeC/C++ Development Tools for NI Linux Real-Time, Eclipse Edition (instead of an external build file) to build the executable.

    Note For purposes of this tutorial, you work only with the Debug configuration, but this section also applies to the Releaseconfiguration.

    (ARM-based targets) Complete the following steps to improve the performance of floating-point operations:Select under in the left pane of the dialog box.Settings C/C++ Build PropertiesSelect under in the tab.Miscellaneous Cross GCC Compiler Tool SettingsIn the text box, add a space after the existing text, and then enterOther flags -mfpu=vfpv3 -mfloat-abi=softfp

    Click and then to close the dialog box.Apply OK PropertiesSelect in the workbench view to create an executable of your project.ProjectBuild Project

  • 7/25/2019 Getting Started With C for Eclipse

    6/126/12 www.ni.c

    9.

    1.

    2.

    3.4.

    5.

    The tab displays if the build completes successfully, as shown in the following image.Console Build Finished

    In the next section of this tutorial, you prepare to run the executable on your NI Linux Real-Time target by adding your target to the

    project.

    6. Configuring a Remote SystemBefore you can run the executable you created in the previous section on your NI Linux Real-Time target, you need to add your

    target to the project. Complete the following steps to configure your target as a remote system in C/C++ Development Tools for N

    Linux Real-Time, Eclipse Edition:

    Note Before proceeding with the steps in this section, ensure your target has SSH enabled. You can enable SSH on your

    target using Measurement & Automation Explorer (MAX) or using a DIP switch on your target (if available).

    Select to open the dialog box.WindowOpen PerspectiveOther Open Perspective

    Select .Remote System Explorer

    Click to add the Remote System Explorer perspective to the workbench.OKClick the button, circled in the following image, to open the New Connection wizard.Define a connection to remote system

    Select under the folder.SSH Only GeneralNote You also can select as the remote system type, but since connecting to NI Linux Real-Time targets requiresLinuxSSH, selecting shortens the number of configuration steps by pre-selecting SSH options.SSH Only

  • 7/25/2019 Getting Started With C for Eclipse

    7/127/12 www.ni.c

    6.7.

    8.

    9.

    0.

    Click to open the page.Next Remote SSH Only System ConnectionSelect a profile to contain the remote system connection from the pull-down menu. For information aboutParent profileprofiles, refer to the topic of theRemote System Explorer Profiles C/C++ Development Tools for NI Linux Real-Time, Eclipse

    , available by selecting from the workbench view.Edition Help HelpHelp ContentsEnter the hostname or IP address of your NI Linux Real-Time target in the text box.Host name

    Tip You can use MAX to identify your target's hostname and IP address.

    (Optional) Enter a description or change the connection name in the and text boxes to helpDescription Connection nameyou identify your target when it appears in the Remote System Explorer perspective.

    Click .Finish

  • 7/25/2019 Getting Started With C for Eclipse

    8/128/12 www.ni.c

    1.

    2.3.

    1.2.3.

    4.5.

    Your target displays in the tab in the Remote System Explorer perspective, as shown in the following imageRemote Systems

    Expand the folder under your target to explore the files on your target.Sftp FilesWhen prompted, enter the user name and password assigned to your target and click . The default user name is anOK adminthe default password is a blank password.

    Note National Instruments recommends you set a password for improved security. For information on setting a password,refer to the topic of the , available by selectingLogging in to your System Measurement & Automation Explorer Help

    from MAX.HelpMAX Help

    Note If the connection pop-up does not include a field, please right-click on your target under theUser ID Remotetab and click You can update the input by changing the option in theSystems Properties. User ID Default User ID Host

    category.

    With a successful logon, you establish an SSH connection to your target and enable transferring files to it. In the next section of

    this tutorial, you copy and run a C/C++ executable on your target.

    7. Running a C/C++ Executable on Your NI Linux Real-Time Target

    At this point in the tutorial, your project contains a target and an executable. Complete the following steps to run your C/C++

    executable on your target:

    Select to open the Run Configurations dialog box.RunRun ConfigurationsSelect in the left pane.C/C++ Remote ApplicationClick the button, circled in the following image, to specify settings for running an executable onNew launch configuration

    your target.

    Select your target from the pull-down menu.ConnectionClick the button beside the text box to open theBrowse Remote Absolute File Path for C/C++ Applications Select Remote

    dialog box.C/C++ Application File

  • 7/25/2019 Getting Started With C for Eclipse

    9/129/12 www.ni.c

    6.

    7.

    8.9.

    Right-click the directory in the listbox and select to create a folder on the target in which to place a copMy Home NewFolder

    of the executable.

    Enter a name for the folder you created in the previous step in the text box.New folder name

    Click to return to the dialog box.Finish Run ConfigurationAppend your project name (or whatever name you wish to assign to the executable) to the file path populated in the Remote

    text box.Absolute File Path for C/C++ ApplicationsNote This text box specifies the file path (including the executable name) on your target where the compiler copies theexecutable. In this example, the file path reads , where/home/admin/ProjectFolder/MyProjectName

    defines the executable name, as shown in the following image.MyProjectName

  • 7/25/2019 Getting Started With C for Eclipse

    10/1210/12 www.ni.c

    0.1.

    1.2.3.4.

    5.

    Click and then to copy and run the executable on your target.Apply RunThe program execution displays in the tab, as shown in the following image.Console

    In the next section of this tutorial, you explore the debugging functionality available in C/C++ Development Tools for NI Linux

    Real-Time, Eclipse Edition.

    8. Debugging a C/C++ Project

    C/C++ Development Tools for NI Linux Real-Time, Eclipse Edition offers functionality for debugging your project. Complete thefollowing steps to debug a C/C++ project in C/C++ Development Tools for NI Linux Real-Time, Eclipse Edition:

    Select to open the dialog box.RunDebug Configurations Debug ConfigurationsSelect the tab.DebuggerClick the button beside the text box.Browse GDB debugger Select the correct debugger as specified in the following list:

    in the(ARM-based targets, 2013 software stack)arm-none-linux-gnueabi-gdb.exe \Eclipse\toolchain\gcc-4.4-arm\i386\bin

    in the(ARM-based targets, 2014 software stack)arm-nilrt-linux-gnueabi-gdb.exe \Eclipse\14.0\arm\sysroots\i686-nilrtsdk-mingw32\usr\bin\armv7a-vfp-neon-nilrt-lindirectory

    in the(Intel x64-based targets, 2014 software stack)x86_64-nilrt-linux-gdb.exe \Eclipse\14.0\x64\sysroots\i686-nilrtsdk-mingw32\usr\bin\x86_64-nilrt-linux

    Click .Open

  • 7/25/2019 Getting Started With C for Eclipse

    11/1211/12 www.ni.c

    6.7.

    Click and then to start debugging the project.Apply DebugClick when C/C++ Development Tools for NI Linux Real-Time, Eclipse Edition, prompts you to switch perspectives.YesExploring the Debug Perspective

    The tab in the upper left displays the call stack of each running thread.Debug

    The tab in the upper right lists C/C++ variables in your source code.Variables

    The project tab in the center left displays source code and highlights lines as they execute.Tip You can hover your cursor over the source code to display detailed information about a function or variable.

    To add a breakpoint, highlight a line of code and select . A breakpoint suspends the execution of aRunToggle Breakpointprogram at the location where the breakpoint is set.

    Exploring the Debug Toolbar

    The Debug toolbar includes the following buttons:

    Instruction SteppingMode Enables instruction stepping mode to examine a program as it steps into disassembled code.

    Drop to Frame Re-enters the selected stack frame in the Debug view.Use Step Filters Enables step filters in the Debug view.

    Step Return Continues execution to the end of the current routine, then follows execution to the caller of theroutine.Step Over Executes the current line, following execution inside a routine.Step Into Executes the current line, including any routines, and proceeds to the next statement.Resume Resumes execution of the currently suspended debug target.Suspend Halts execution of the currently selected thread in a debug target.Terminate Ends the selected debug session and/or process.Disconnect Detaches the debugger from the selected process.

    9. Related Information

    C/C++ Embedded System Design Tools (http://digital.ni.com/express.nsf/bycode/exn9da)

    C Support for myRIO (http://digital.ni.com/express.nsf/bycode/CmyRIO)

    10. Legal Information

    Copyright

    20132015 National Instruments. All rights reserved.

    Under the copyright laws, this publication may not be reproduced or transmitted in any form, electronic or mechanical, including

    photocopying, recording, storing in an information retrieval system, or translating, in whole or in part, without the prior written

    consent of National Instruments Corporation.

    National Instruments respects the intellectual property of others, and we ask our users to do the same. NI software is protected by

    copyright and other intellectual property laws. Where NI software may be used to reproduce software or other materials belonging

    to others, you may use NI software only to reproduce materials that you may reproduce in accordance with the terms of any

    applicable license or other legal restriction.

    End-User License Agreements and Third-Party Legal Notices

    You can find end-user license agreements (EULAs) and third-party legal notices in the following locations after installation:

    Notices are located in the and\_Legal Information

    directories.

    http://digital.ni.com/express.nsf/bycode/exn9dahttp://digital.ni.com/express.nsf/bycode/CmyRIOhttp://digital.ni.com/express.nsf/bycode/CmyRIOhttp://digital.ni.com/express.nsf/bycode/exn9da
  • 7/25/2019 Getting Started With C for Eclipse

    12/12

    EULAs are located in the directory.\Shared\MDF\Legal\license

    Review for information on including legal information in installers\_Legal Information.txtbuilt with NI products.

    U.S. Government Restricted Rights

    If you are an agency, department, or other entity of the United States Government ("Government"), the use, duplication,

    reproduction, release, modification, disclosure or transfer of the technical data included in this manual is governed by the

    Restricted Rights provisions under Federal Acquisition Regulation 52.227-14 for civilian agencies and Defense Federal Acquisitio

    Regulation Supplement Section 252.227-7014 and 252.227-7015 for military agencies.

    IVI Foundation Copyright Notice

    Content from the IVI specifications reproduced with permission from the IVI Foundation.The IVI Foundation and its member companies make no warranty of any kind with regard to this material, including, but not limited

    to, the implied warranties of merchantability and fitness for a particular purpose. The IVI Foundation and its member companies

    shall not be liable for errors contained herein or for incidental or consequential damages in connection with the furnishing,

    performance, or use of this material.

    Trademarks

    Refer to the at forNI Trademarks and Logo Guidelines ni.com/trademarks (http://digital.ni.com/express.nsf/bycode/rdtrad)

    information on trademarks. Other product and company names mentioned herein are trademarks or tradeNational Instruments

    names of their respective companies.

    Eclipse is a trademark of Eclipse Foundation, Inc.

    Patents

    For patents covering the National Instruments products/technology, refer to the appropriate location: in yourHelpPatents

    software, the file on your media, or the atpatents.txt National Instruments Patent Notice ni.com/patents (

    .http://digital.ni.com/express.nsf/bycode/rdlv17)

    Customer Reviews

    1 Review | Submit your review (

    http://zone.ni.com/apps/utf8/nidz_display_comments.create_comment?p_title=Getting+Started+with+C%2FC%2B%2B+Developm

    )

    COMPANY

    About National Instruments (http://www.n

    Events (http://www.ni.com/events/)

    Careers (http://www.ni.com/careers/)

    SUPPORT

    Submit a service request (https://sine.ni.com/srm/app/myServiceRequests)

    Manuals (http://www.ni.com/manuals/)

    Drivers (http://www.ni.com/downloads/drivers/)

    Alliance Partners (http://www.ni.com/alliance/)

    PRODUCT

    Order status and history (http://www.ni.com/status/)

    Order by part number (http://sine.ni.com/apps/utf8/nios.store?action=purchase_form)

    Activate a product (http://sine.ni.com/myproducts/app/main.xhtml?lang=en)

    Order and payment information (http://www.ni.com/how-to-buy/)

    MISSION

    NI equips engineers and scientists with systems that accelerate productivity, innovation, and discovery.

    (http://twitter.com/niglobal) (http://www.facebook.com/NationalInstruments) (http://www.linkedin.com/company/3433?trk=tyah)

    (http://www.youtube.com/nationalinstruments)

    Contact Us (http://www.ni.com/contact-us/)

    National Instruments. All rights reserved.Legal (http://www.ni.com/legal/) | | Site map (

    http://www.ni.com/help/map.htm)

    (http://privacy.truste.com/privacy-seal/National-Instruments-Corporation/validation?rid=bc6daa8f-7051-4eea-b7b5-fb24dcd96d95)

    http://digital.ni.com/express.nsf/bycode/rdtradhttp://digital.ni.com/express.nsf/bycode/rdlv17http://digital.ni.com/express.nsf/bycode/rdlv17http://zone.ni.com/apps/utf8/nidz_display_comments.create_comment?p_title=Getting+Started+with+C%2FC%2B%2B+Development+Tools+for+NI+Linux+Real-Time%2C+Eclipse+Edition&p_doc_id=DZTUT-14625-EN&p_doc_type=DZTUT&p_url=http://www.ni.com/tutorial/14625/en&p_doc_url_id=14625http://zone.ni.com/apps/utf8/nidz_display_comments.create_comment?p_title=Getting+Started+with+C%2FC%2B%2B+Development+Tools+for+NI+Linux+Real-Time%2C+Eclipse+Edition&p_doc_id=DZTUT-14625-EN&p_doc_type=DZTUT&p_url=http://www.ni.com/tutorial/14625/en&p_doc_url_id=14625http://zone.ni.com/apps/utf8/nidz_display_comments.create_comment?p_title=Getting+Started+with+C%2FC%2B%2B+Development+Tools+for+NI+Linux+Real-Time%2C+Eclipse+Edition&p_doc_id=DZTUT-14625-EN&p_doc_type=DZTUT&p_url=http://www.ni.com/tutorial/14625/en&p_doc_url_id=14625http://www.ni.com/company/http://www.ni.com/events/http://www.ni.com/careers/https://sine.ni.com/srm/app/myServiceRequestshttps://sine.ni.com/srm/app/myServiceRequestshttp://www.ni.com/manuals/http://www.ni.com/downloads/drivers/http://www.ni.com/alliance/http://www.ni.com/status/http://sine.ni.com/apps/utf8/nios.store?action=purchase_formhttp://sine.ni.com/apps/utf8/nios.store?action=purchase_formhttp://sine.ni.com/myproducts/app/main.xhtml?lang=enhttp://sine.ni.com/myproducts/app/main.xhtml?lang=enhttp://www.ni.com/how-to-buy/http://twitter.com/niglobalhttp://www.facebook.com/NationalInstrumentshttp://www.linkedin.com/company/3433?trk=tyahhttp://www.youtube.com/nationalinstrumentshttp://www.ni.com/contact-us/http://www.ni.com/legal/http://www.ni.com/help/map.htmhttp://www.ni.com/help/map.htmhttp://privacy.truste.com/privacy-seal/National-Instruments-Corporation/validation?rid=bc6daa8f-7051-4eea-b7b5-fb24dcd96d95http://privacy.truste.com/privacy-seal/National-Instruments-Corporation/validation?rid=bc6daa8f-7051-4eea-b7b5-fb24dcd96d95http://privacy.truste.com/privacy-seal/National-Instruments-Corporation/validation?rid=bc6daa8f-7051-4eea-b7b5-fb24dcd96d95http://www.ni.com/help/map.htmhttp://www.ni.com/help/map.htmhttp://www.ni.com/help/map.htmhttp://www.ni.com/help/map.htmhttp://www.ni.com/legal/http://www.ni.com/legal/http://www.ni.com/contact-us/http://www.ni.com/contact-us/http://www.youtube.com/nationalinstrumentshttp://www.ni.com/rss/http://www.linkedin.com/company/3433?trk=tyahhttp://www.facebook.com/NationalInstrumentshttp://twitter.com/niglobalhttp://www.ni.com/how-to-buy/http://sine.ni.com/myproducts/app/main.xhtml?lang=enhttp://sine.ni.com/myproducts/app/main.xhtml?lang=enhttp://sine.ni.com/myproducts/app/main.xhtml?lang=enhttp://sine.ni.com/apps/utf8/nios.store?action=purchase_formhttp://sine.ni.com/apps/utf8/nios.store?action=purchase_formhttp://sine.ni.com/apps/utf8/nios.store?action=purchase_formhttp://www.ni.com/status/http://www.ni.com/alliance/http://www.ni.com/downloads/drivers/http://www.ni.com/manuals/https://sine.ni.com/srm/app/myServiceRequestshttps://sine.ni.com/srm/app/myServiceRequestshttps://sine.ni.com/srm/app/myServiceRequestshttp://www.ni.com/careers/http://www.ni.com/events/http://www.ni.com/company/http://zone.ni.com/apps/utf8/nidz_display_comments.create_comment?p_title=Getting+Started+with+C%2FC%2B%2B+Development+Tools+for+NI+Linux+Real-Time%2C+Eclipse+Edition&p_doc_id=DZTUT-14625-EN&p_doc_type=DZTUT&p_url=http://www.ni.com/tutorial/14625/en&p_doc_url_id=14625http://zone.ni.com/apps/utf8/nidz_display_comments.create_comment?p_title=Getting+Started+with+C%2FC%2B%2B+Development+Tools+for+NI+Linux+Real-Time%2C+Eclipse+Edition&p_doc_id=DZTUT-14625-EN&p_doc_type=DZTUT&p_url=http://www.ni.com/tutorial/14625/en&p_doc_url_id=14625http://zone.ni.com/apps/utf8/nidz_display_comments.create_comment?p_title=Getting+Started+with+C%2FC%2B%2B+Development+Tools+for+NI+Linux+Real-Time%2C+Eclipse+Edition&p_doc_id=DZTUT-14625-EN&p_doc_type=DZTUT&p_url=http://www.ni.com/tutorial/14625/en&p_doc_url_id=14625http://zone.ni.com/apps/utf8/nidz_display_comments.create_comment?p_title=Getting+Started+with+C%2FC%2B%2B+Development+Tools+for+NI+Linux+Real-Time%2C+Eclipse+Edition&p_doc_id=DZTUT-14625-EN&p_doc_type=DZTUT&p_url=http://www.ni.com/tutorial/14625/en&p_doc_url_id=14625http://digital.ni.com/express.nsf/bycode/rdlv17http://digital.ni.com/express.nsf/bycode/rdlv17http://digital.ni.com/express.nsf/bycode/rdlv17http://digital.ni.com/express.nsf/bycode/rdtrad