May 11, 2017

Build / Debug c/c++ synchronized projects behind ssh remote gateway via Eclipse ( Client-Server type)

I found tunneling a remote gateway very slow and figured out a better way to work with synchronized projects. {This is very easy  via ssh with -xy enabled on server and tunnel through x-window system (Xming For windows)}.
Login as
ssh -XY username@xx.yy.org in both the gateway and the machine.


I couldn't find a way to use Netbeans for remote C/C++/Fortran projects with a gateway yet. Below method is using  Eclipse for linux or windows.


Files you have  edit

Remote:

 Your bashrc script or bash_profile - This  is hidden in /home/username
                                  Do : ll  -a  then vi  bash_profile
 Remote development by synchronized projects uses git. You need git installed on your remote machine. So we need to add the lines below to the end of your bash_profile script.


module load git
git config --global pack.windowMemory "100m"
git config --global pack.SizeLimit "100m"
git config --global pack.threads "1"

Local:
Eclipse seem to support Git inherently. So we only need to install eclipse  neon for parallel C/C++ development


Eclipse settings --------------------------------------------------------------------------------

Goto Window>Preferences>Add


Add your gateway as the first connection. Give the Host name and your username. ( equivalent to , ssh username@host.org etc). Connection name could be anything you want. Here I set it as 'xcams gateway'.Choose password based connection, if you want to use a password. Then click finish.


Next we add the actual connection that is behind the gateway. Click Add a new connection again.
Give the connection name , host and username as before. Then click Advanced. In SSH Proxy settings, click Remote, and select the Gateway we created before. Now click finish. 


Then click open button on the right hand side. This will open up the connection. If you didn't save your password, you have to enter the password now.

Next go to menu File>New>Other from the menu.


Then select Synchronized C/C++ projects from 'Other'.                                                                          


Click Next. Then select the ssh connection (not the gateway).                                                               



Then select the Remote directory by clicking 'Browse' button.                                                             


Then Click the project folder you want to synchronize with.                                                                
                                                     

Click ok. Give the Project name the same name as the project you selected.                                      

Select the project type as GNU Auto Tools (This could be different depending on your project.) and select 'Empty project'. 
**I had to do little bit more settings on windows to work because we need to support cross compilation with windows and our Linux based remote system. But it just works if you are using a linux machine.


Now choose to synchronize the project by right clicking on it unless auto sync is on by default. Screen shot is a windows system. But on Linux you need to specifically set it to sync. This may take a while if you have a rather large system on the remote machine.

                                                                     

** On windows 10 (This should be available on most windows OS) 
goto control panel> Turn windows features on >           
Click the check box saying, Windows subsystem for Linux

{This step is not necessary on Ubuntu}



                                                       




 credit: https://www.earthsystemcog.org/projects/cupid/proxyconnections and the great WWW!



******************************************************************************
More on setting up include paths for the remote synchronized project to run using remote machine:

(If needed, Click the link to goto eclipse help location which I'm quoting below )

"There are several places where include files are important to the editing, analyzing, building, and running of your program. A Synchronized Project mirrors the source files on the local machine as well as the remote target machine. Usually you edit locally, but build and run on the remote target. So this complicates things with respect to include files.
    By default, a synchronized project uses the normal CDT discovery mechanism, which reads the local environment. To configure the new discovery elements, follow these instructions after creating a new synchronized project. Go to Project > Properties > C/C++ General > Preprocessor Include Paths, Macros etc. Make sure the remote configuration is selected at the top of the dialog. Under the Providers tab, deselect all CDT providers, except for "CDT User Setting Entries" if you would like to enter your own paths. Next, select the two Sync providers, "Sync GCC Build Output Parser" and "Sync GCC Builtin Compiler Settings." The latter provider runs a specially-crafted compiler command to get compiler-specific settings. It will run immediately after "OK" is selected. The former provider will execute simultaneously with builds. It intercepts the build output and attempts to find environment information. Thus, a build must be run before this provider is useful.

    Now, make sure that indexing is enabled and invoke a remote build. In order for the build output parser to be useful, builds must produce verbose output. The method for setting up such a build varies per project, but see the Mozilla Project CDT setup page for a good example. Repeat these steps for each remote build configuration. For local configurations, both the standard CDT or new Sync providers should work. If you would like the environment to update automatically when build configurations are switched, go to Project > Properties > C/C++ General > Indexer and select "Use active build configuration" for "Build configuration for the indexer." The downside of this is that the indexer will run each time you switch configurations."


    Here if you are connecting through a gateway remember to use the name of the ssh connection (2nd) instead of the full path name. Otherwise Eclipse tries to
    login to the machine directly.

    E.g: See below. Instead of using //nxxx.x.org/opt/../include use //ConnectionName/opt/../include when you set include files from remote location.




    2 comments:

    1. I had trouble with modules not loaded at the startup so had to add the modules I needed in addition to git at startup, by editing .bash_profile

      ReplyDelete
    2. When trying to "Sync all now", I am getting an error. The stack trace is:

      java.lang.NoSuchMethodError: org.eclipse.jgit.lib.Repository.getRef(Ljava/lang/String;)Lorg/eclipse/jgit/lib/Ref;
      at org.eclipse.ptp.internal.rdt.sync.git.core.JGitRepo.merge(JGitRepo.java:605)
      at org.eclipse.ptp.internal.rdt.sync.git.core.GitSyncService.doSyncRL(GitSyncService.java:720)
      at org.eclipse.ptp.internal.rdt.sync.git.core.GitSyncService.doSync(GitSyncService.java:627)
      at org.eclipse.ptp.internal.rdt.sync.git.core.GitSyncService.synchronize(GitSyncService.java:529)
      at org.eclipse.ptp.rdt.sync.core.SyncManager$SynchronizeJob.run(SyncManager.java:79)
      at org.eclipse.core.internal.jobs.Worker.run(Worker.java:63)

      Any idea why this might be happening? Is it looking for a method that doesn't exist, if so is this happening on the remote or local side and do you have any idea how to solve this or have you encountered it before?

      Thank you,

      Tom

      ReplyDelete

    Followers