{"id":1145,"date":"2013-09-20T10:23:57","date_gmt":"2013-09-20T10:23:57","guid":{"rendered":"https:\/\/raspberry-projects.com\/pi\/?p=1145"},"modified":"2014-09-26T15:05:13","modified_gmt":"2014-09-26T15:05:13","slug":"create-new-eclipse-project-for-the-rpi","status":"publish","type":"post","link":"https:\/\/raspberry-projects.com\/pi\/programming-in-c\/compilers-and-ides\/eclipse\/create-new-eclipse-project-for-the-rpi","title":{"rendered":"Create New Eclipse Project For The RPi"},"content":{"rendered":"<p>\n&nbsp;\n<\/p>\n<h4>\nCreating A&nbsp;New Eclipse Project<br \/>\n<\/h4>\n<p>\nEclipse uses workspaces, which is simply a folder where you have one or more projects. You can switch workspace to a new workspace so if you want to you can simply start with a workspace that has a single project and change to a new workspace when you want to work on a different project. &nbsp;Workspaces can use long paths and have space characters in names etc (no funny restrictions we&#39;ve come across)\n<\/p>\n<h5>\nCreate A Project<br \/>\n<\/h5>\n<p>\nFollow this to create a blank project &#8211; if you have existing&nbsp;files to add leave doing that until you have completed all of the steps.\n<\/p>\n<p>\nOpen Eclipse (Right click the eclipse.exe in the C:\\eclipse folder and run as administrator). &nbsp;For the workspace prompt select the directory where you will be creating your project, e.g. &quot;C:\\My Project\\firm\\V1-00&quot;\n<\/p>\n<p>\nFile &gt; New &gt; C++ Project\n<\/p>\n<p style=\"margin-left: 40px;\">\nGive the project a name\n<\/p>\n<p style=\"margin-left: 40px;\">\nHello World C++ Project\n<\/p>\n<p style=\"margin-left: 40px;\">\nCross GCC\n<\/p>\n<p style=\"margin-left: 40px;\">\nEverything else as default.\n<\/p>\n<p style=\"margin-left: 40px;\">\nRight click the project in Project Explorer &gt; Properties\n<\/p>\n<p>\nYou should see the new project IDE. &nbsp;If not make sure this button is pressed:\n<\/p>\n<p style=\"margin-left: 40px;\">\n<a href=\"https:\/\/raspberry-projects.com\/pi\/wp-content\/uploads\/2012\/10\/eclipse_show_project_button.png\"><img loading=\"lazy\" decoding=\"async\" alt=\"eclipse_show_project_button\" class=\"alignnone size-full wp-image-1062\" height=\"127\" src=\"https:\/\/raspberry-projects.com\/pi\/wp-content\/uploads\/2012\/10\/eclipse_show_project_button.png\" width=\"45\" \/><\/a>\n<\/p>\n<p>\nConfigure it as follows, by right clicking the project name in the Project Explorer and selecting properties:<br \/>\nC\/C++ Build &gt; Environment\n<\/p>\n<ul>\n<li>\nAdd a variable named CYGWIN with value nodosfilewarning (tick &#39;add to all configurations&#39;)\n<\/li>\n<li>\nAppend the following to the beginning of the PATH variable: c:\\cygwin\\opt\\cross\\x-tools\\arm-unknown-linux-gnueabi\\bin;c:\\cygwin\\bin;\n<\/li>\n<\/ul>\n<p>\nC\/C++ Build &gt; Tool Chain Editor\n<\/p>\n<ul>\n<li>\nSelect Cygwin GCC from Current toolchain dropbox.\n<\/li>\n<\/ul>\n<p>\nC\/C++ Build &gt; Settings &gt; Tool Settings\n<\/p>\n<ul>\n<li>\nSet the Command field in Cygwin C++ Compiler to: arm-unknown-linux-gnueabi-g++\n<\/li>\n<li>\nAdd an include path (not include files) in Includes which points to: c:\\cygwin\\opt\\cross\\x-tools\\arm-unknown-linux-gnueabi\\arm-unknown-linux-gnueabi\\sysroot\\usr\\include\n<\/li>\n<\/ul>\n<ul>\n<li>\nSet the Command field in Cygwin C Compiler to: arm-unknown-linux-gnueabi-g++\n<\/li>\n<li>\nAdd an include path (not include files) in Includes which points to: c:\\cygwin\\opt\\cross\\x-tools\\arm-unknown-linux-gnueabi\\arm-unknown-linux-gnueabi\\sysroot\\usr\\include\n<\/li>\n<\/ul>\n<ul>\n<li>\nSet the Command field in Cygwin C++ Linker to: arm-unknown-linux-gnueabi-g++\n<\/li>\n<li>\nAdd a library search path (not Libraries) in Libraries which points to: c:\\cygwin\\opt\\cross\\x-tools\\arm-unknown-linux-gnueabi\\arm-unknown-linux-gnueabi\\sysroot\\usr\\lib\n<\/li>\n<\/ul>\n<p>\nC\/C++ Build &gt; Settings &gt; Build Steps\n<\/p>\n<ul>\n<li>\nSet the Command field in Post-build steps to: C:\/eclipse\/deployment_scripts\/rpi_deploy_debug.bat $(OutDir)${ProjName}.a &quot;\/home\/pi\/projects\/${ProjName}.a&quot;\n<\/li>\n<li>\nAdd the description field to: Our auto deploy to RPi using putty script\n<\/li>\n<\/ul>\n<p>\nC\/C++ Build &gt; Settings &gt; Build Artifact\n<\/p>\n<ul>\n<li>\nSet Artifact Extension to: a\n<\/li>\n<\/ul>\n<p>\nPress OK\n<\/p>\n<h5>\nCompiling<br \/>\n<\/h5>\n<p>\n(Tested with Eclipse V4.2 Juno)<br \/>\nProject &gt; Build All (or Project &gt; Build Project if &quot;Build All&quot; is not available)\n<\/p>\n<p>\nThe project should compile without errors at this point.\n<\/p>\n<h5>\nProblems<br \/>\n<\/h5>\n<ul>\n<li>\nIf the&nbsp;PuTTY&nbsp;window hangs just close it and confirm the close session box if it asks if you are sure. &nbsp;This is not a problem and putty remains working in the background.\n<\/li>\n<li>\nTrying running eclipse by right clicking eclipse.exe and selecting &#39;Run as administrator&#39;.\n<\/li>\n<li>\nIf you get \/usr\/bin\/sh: g++: command not found errors you can right click the project &gt; Properties &gt; C\/C++ Build &gt; Discovery Options and turn off &#39;Automate discovery of paths and symbols for both of the&nbsp;Cygwin tools listed. &nbsp;However this shouldn&#39;t be necessary.\n<\/li>\n<li>\nIf you get other errors then go through and check the previous steps have been followed precisely.\n<\/li>\n<li>\nOpening workspace project not shown &#8211; you may need to press this button to see the project:<br \/>\n<a href=\"https:\/\/raspberry-projects.com\/pi\/wp-content\/uploads\/2012\/10\/eclipse_show_project_button.png\"><img loading=\"lazy\" decoding=\"async\" alt=\"eclipse_show_project_button\" class=\"alignnone size-full wp-image-1062\" height=\"127\" src=\"https:\/\/raspberry-projects.com\/pi\/wp-content\/uploads\/2012\/10\/eclipse_show_project_button.png\" width=\"45\" \/><\/a>\n<\/li>\n<li>\nEclipse can be buggy. Try restarting it, or closing it then creating a new project to see if the problem magically vanishes (it sometimes does!).\n<\/li>\n<\/ul>\n<p>\nIf everything went smoothly select the Console output view in Eclipse and it should have printed something about the binary uploading and command execution.\n<\/p>\n<h5>\nProblems<br \/>\n<\/h5>\n<p style=\"font-size: 10px;\">\nDelete&nbsp;the file on the&nbsp;RPi&nbsp;and then re-build\n<\/p>\n<p style=\"font-size: 10px;\">\nHangs with&nbsp;PuTTY&nbsp;window open &#8211; just close it (it still runs in the background)\n<\/p>\n<h4>\nDebugging With Eclipse<br \/>\n<\/h4>\n<p>\n<em>The following is a re-workign of our original non working&nbsp;instructions&nbsp;following the solution found by&nbsp;<\/em>ChristianM&nbsp;&#8211; thanks Christian!\n<\/p>\n<h5>\nCreating A Remote Connection<br \/>\n<\/h5>\n<p>\nIf you&#39;ve not proviously created a remote connection called&nbsp;remote_rpi (you can look in Menu &gt; Window &gt; Show View &gt; Other &gt; Remote Systems &gt; Remote Systems) then create one first:\n<\/p>\n<p style=\"margin-left: 40px;\">\nMenu &gt; File &gt; New &gt; Other &gt; Remote System Explorer &gt; Connection<br \/>\nSSH Only<br \/>\nHost name: The IP address of the RPi<br \/>\nConnection name: remote_rpi<br \/>\nRest default (just press finish)\n<\/p>\n<h5>\nSetup Debugging<br \/>\n<\/h5>\n<p>\nNow setup a Debug Configuration.<br \/>\nSelect Menu Run &gt; Debug configurations from the top menu.<br \/>\nRight click on C\/C++ Remote Application and choose New to add a new configuration.\n<\/p>\n<p>\nMain tab\n<\/p>\n<ul>\n<li>\nSet &nbsp;&quot;C\/C++ Application field&quot; to&nbsp;the name of the produced binary:&nbsp;Debug\/${project_name}.a\n<\/li>\n<li>\nSelect Disable auto build.\n<\/li>\n<li>\nClick on Select other&hellip;, near the left of the Apply button. From the newly opened window, choose GDB (DSF) Automatic Remote Debugging Launcher and click ok.\n<\/li>\n<li>\nRemote Absolute File Path for C\/C++ Application: Set to the path where the application will be running on the Raspberry, e.g. \/home\/pi\/projects\/my_project.a &nbsp; &nbsp;(you can&#39;t use ${ProjName} or ${project_name} here)\n<\/li>\n<li>\n&quot;Connection:&quot; drop down box: Select the &quot;remote_rpi&quot; connection you made.\n<\/li>\n<\/ul>\n<p>\nDebugger tab\n<\/p>\n<ul>\n<li>\nSet the GDB debugger field to the path of the gdb which is part of our downloaded tool chain, so: c:\\cygwin\\opt\\cross\\x-tools\\arm-unknown-linux-gnueabi\\bin\\arm-unknown-linux-gnueabi-gdb.exe\n<\/li>\n<\/ul>\n<p>\nSource tab\n<\/p>\n<ul>\n<li>\nAdd &gt; Path mapping.\n<\/li>\n<li>\nName it &quot;Cygwin C Drive&quot; and in Compilation Path enter: \/cygdrive\/c\/\n<\/li>\n<li>\nIn Local file system path enter: C:\\\n<\/li>\n<\/ul>\n<p>\nClick on Apply and then Close.&nbsp;\n<\/p>\n<p>\n&nbsp;\n<\/p>\n<p>\nTo leave the debug perspective (mode) use Window &gt; Open Perspective &gt; C\/C++<br \/>\nTo come back use Window &gt; Open Perspective &gt; Debug<br \/>\n&nbsp;\n<\/p>\n<p>\nTo Debug your project select &quot;Debug&quot; from the Menu &gt; Run &gt; Debug Configurations, or Menu &gt; Run &gt; Debug Histroy &gt; rpi Debug\n<\/p>\n<h5>\nProblems<br \/>\n<\/h5>\n<p>\nDelete&nbsp;the file on the RPi and then re-build\n<\/p>\n<h4>\nSetup Required On The Raspberry Pi<br \/>\n<\/h4>\n<p style=\"font-size: 10px;\">\nIn the &quot;C\/C++ Build &gt; Settings &gt; Build Steps&quot; step above the target for the putty transfer is set to &quot;\/home\/pi\/projects\/${ProjName}.a&quot;. &nbsp;You need to create this \/projects\/ directory on the&nbsp;RPi&nbsp;for the project .a file to be transferred&nbsp;into, so use this at the&nbsp;RPi&nbsp;command line:\n<\/p>\n<pre style=\"font-size: 10px;\">\r\n<code>mkdir projects<\/code><\/pre>\n<p style=\"font-size: 10px;\">\nTo run it see&nbsp;<a href=\"https:\/\/raspberry-projects.com\/pi\/programming-in-c\/running-your-exe\">here<\/a>.\n<\/p>\n<h4>\nEclipse Settings<br \/>\n<\/h4>\n<p style=\"font-size: 10px;\">\nSave files before build needs turning on:\n<\/p>\n<p style=\"font-size: 10px; margin-left: 40px;\">\nWindow &gt; Preferences &gt;&nbsp;General &gt; Workspace. &nbsp;Check &#39;Save automatically before build&#39;.\n<\/p>\n<h4>\nAdding The IO Library To Eclipse<br \/>\n<\/h4>\n<p style=\"font-size: 10px;\">\nSee&nbsp;<a href=\"https:\/\/raspberry-projects.com\/pi\/programming-in-c\/compilers-and-ides\/eclipse\/eclipse-general-notes\" target=\"_blank\">here<\/a>\n<\/p>\n<p>\n&nbsp;\n<\/p>\n<p>\n&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>&nbsp; Creating A&nbsp;New Eclipse Project Eclipse uses workspaces, which is simply a folder where you have one or more projects. You can switch workspace to a new workspace so if you want to you can simply start with a workspace that has a single project and change to a new workspace when you want to [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[17],"tags":[],"class_list":["post-1145","post","type-post","status-publish","format-standard","hentry","category-eclipse"],"_links":{"self":[{"href":"https:\/\/raspberry-projects.com\/pi\/wp-json\/wp\/v2\/posts\/1145","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/raspberry-projects.com\/pi\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/raspberry-projects.com\/pi\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/raspberry-projects.com\/pi\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/raspberry-projects.com\/pi\/wp-json\/wp\/v2\/comments?post=1145"}],"version-history":[{"count":11,"href":"https:\/\/raspberry-projects.com\/pi\/wp-json\/wp\/v2\/posts\/1145\/revisions"}],"predecessor-version":[{"id":1727,"href":"https:\/\/raspberry-projects.com\/pi\/wp-json\/wp\/v2\/posts\/1145\/revisions\/1727"}],"wp:attachment":[{"href":"https:\/\/raspberry-projects.com\/pi\/wp-json\/wp\/v2\/media?parent=1145"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/raspberry-projects.com\/pi\/wp-json\/wp\/v2\/categories?post=1145"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/raspberry-projects.com\/pi\/wp-json\/wp\/v2\/tags?post=1145"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}