How to Open Definition in GoClipse

The Open Definition operation in a default installation of Go and GoClipse does not work. This functionality of being able to jump to the definition of a type or function is provided by a tool named godef.

  • Installing godef is easy:
$ go get -v github.com/rogpeppe/godef

This installs a godef binary in the $GOPATH/bin directory.

  • Open Window -> Preferences -> Go -> Tools and set the path to the godef binary here.

  • Restart Eclipse. Right-click on any member or function and choose Open Definition, it should work now!

Note that GoClipse still does not provide the useful feature of showing details of a type or function in tooltip when you hover over something in the source file.

Tried with: GoClipse 0.14.1, Eclipse 4.5.2, Go 1.6.2 and Ubuntu 14.04

How to get Outline in GoClipse

GoClipse cannot show the Outline of a Go source file with just a default installation of Go. You will find that the Outline view is empty and pressing Ctrl + O to get an Outline throws up an error. For Go, the Outline is generated using a tool called Oracle.

  • Install Oracle:
$ go get golang.org/x/tools/cmd/oracle

This installs an oracle binary file in $GOPATH/bin directory

  • Open Windows -> Preferences -> Go -> Tools and set the path of Oracle.

  • Restart GoClipse. Outline view should show the details for your currently open source file now.

Tried with: GoClipse 0.14.1, Eclipse 4.5.2, Go 1.6.2 and Ubuntu 14.04

How to get autocomplete in GoClipse

Problem

I installed the Go compiler and set the GOROOT and GOPATH environment variables correctly. To work with Go files, I installed the GoClipse plugin in Eclipse. When I tried to make Goclipse autocomplete my code, I got this error:

Cannot run program "gocode": error=2, No such file or directory

Solution

The Go compiler is not typically used for autocompletion. There is a separate gocode tool that is used for this purpose. So, to get autocompletion we need to install this by using this command:

$ go get -u github.com/nsf/gocode

I found that this installed the gocode binary in $GOPATH/bin. I opened Window -> Preferences -> Go -> Tools and set this path for gocode. Autocompletion started working immediately after this! 🙂

Tried with: GoClipse 0.14.1, Eclipse 4.5.2 and Go 1.6.2

Cache file could not be renamed error

Problem

I installed a fresh copy of Eclipse. I opened its Update Software section to install some software. The Mars section took forever to load and in the end threw this error:

Unable to read repository at http://download.eclipse.org/releases/mars.
An error occurred while downloading http://download.eclipse.org/releases/mars/201506241002/content.xml.xz.
The cache file /home/joe/eclipse/p2/org.eclipse.equinox.p2.repository/cache/downloading/467561694 could not be renamed to /home/joe/eclipse_/p2/org.eclipse.equinox.p2.repository/cache/467561694.

Solution

This error persisted no matter if I restarted Eclipse. In the end, I just deleted the p2/org.eclipse.equinox.p2.repository/cache directory. The software list uploaded fine after that.

Tried with: Eclipse 4.5 and Ubuntu 14.04

How to exclude files from Eclipse indexer

The Indexer in Eclipse CDT runs in the background indexing the source files of your project. Indexer is one of the main reasons Eclipse can be slow. You can see it churning away in the background most of the time.

If you have a lot of files in your project that you do not want to be indexed, that would ease the load on the indexer and make your Eclipse user experience better. To exclude such files from Indexer:

  • Go to project Properties -> C/C++ General -> Paths and Symbols.

  • Go to Source Location tab, click on your project name and choose Edit Filter.

  • In the Edit Filter dialog, add the files you want to be excluded from indexing.

Tried with: Eclipse 4.5 (Mars) and Ubuntu 14.04

OpenGL functions not resolved in Eclipse

Problem

In Eclipse, I am able to build and run C++ code that calls OpenGL functions. However, most of the OpenGL calls are marked as could not be resolved by the Indexer in Eclipse.

Solution

Almost all of the modern OpenGL functions are defined behind the GL_GLEXT_PROTOTYPES symbol in header files such as gl.h and glext.h. We need to define this symbol for the Indexer.

Go to project Properties -> C/C++ General -> Paths and Symbols. Under the Symbols tab, add a new symbol with the Name as GL_GLEXT_PROTOTYPES. No value needs to be provided. Rebuild the index for the project and the unresolved indications for OpenGL functions should be gone!

Tried with: Eclipse 4.5 and Ubuntu 14.04

How to change compiler options used by indexer in Eclipse CDT

Eclipse CDT understands the C++ code in a window by running it through an indexer. This indexer is nothing but an invocation of the GCC C++ compiler with certain compilation options. Sometimes, you might want to change the compiler options used by this indexer.

For example, I recently found that C++11 containers and classes (like future) were not resolved by the indexer and were underlined with red squiggles. This is because the compiler options used by the indexer does not have -std=c++11.

To change the compiler options of the indexer:

  1. Open Preferences and go to C/C++ -> Build -> Settings.
  2. Click the Discovery tab and choose CDT GCC Built-in Compiler Settings.
  3. Modify the command string shown below it as you wish. For example, here I added -std=c++11.
  4. Eclipse CDT will automatically re-index your C++ files after this is saved. However, I found that this did not remove the unresolved items.
  5. I manually re-indexed by right-clicking the project and choosing Index -> Rebuild. This worked!

Tried with: Eclipse 4.5 (Mars) and Ubuntu 14.04

Spellcheck in Eclipse

Eclipse has support for doing spellcheck of words in code or comments.

  • The configuration is handled from Preferences -> General -> Editors -> Text Editors -> Spelling. (Note: This dialog has some display problem and renders a very long page. Scroll down slowly to be able to view all the items.)
  • In the Options, you can choose all the cases where spellcheck can be ignored.
  • In the Dictionaries section, you can choose the language dictionary to use (I use English (United States). You can also pick a text file to use when you add your own words to dictionary. (I like to point this to my Vim text spellfile.) You can also choose the Encoding (I pick UTF-8).
  • Misspelt words appear in the editor underlined with a red squiggle. Right-click to fix the misspelling or add the word to your dictionary.

Tried with: Eclipse 4.5 and Ubuntu 14.04

Unresolved inclusion warning in Eclipse

20150901_unresolved_inclusion

Problem

When working with C++ code in Eclipse, you might see a Unresolved inclusion warning for some include header lines. This is indicated with a question-mark and an underline squiggle. On hovering the mouse over it, a tooltip is shown with the Unresolved inclusion message.

Solution

This is caused when the Eclipse indexer cannot find the header file you have included. This commonly happens when you have installed the library of that header file in a non-standard location.

  1. Open the project Properties and go to C/C++ General -> Paths and Symbols.
  2. In the Includes tab, go to the GNU C++, choose Add and add the path to the directory that contains the above header file.
  3. After re-indexing the code of your project, this warning should be gone.

Tried with: Eclipse 4.5 and Ubuntu 14.04

Out of sync error in Eclipse

Problem

Eclipse has a strange behavior that I have not seen in any other editor or IDE. Assume that a file belonging to a project in the workspace has been modified outside of Eclipse. If you now open that file in Eclipse, it does not open it, but shows this error:

Resource is out of sync with the file system: '/src/foo.cpp'.

Press 'F5' or select File > Refresh to refresh the file.

You can press F5 and the file will be displayed.

Solution

I cannot imagine a scenario in practice where I would not want to keep the updated file. To make this out of sync error go away by refreshing files automatically, you have two options:

  1. You can make Eclipse refresh the file automatically when it is opened. To do this enable Windows -> Preferences -> General -> Workspace -> Refresh on access.

  2. You can make Eclipse refresh the file by being signaled by the filesystem (this is efficient) or polling the filesystem (this is inefficient). This is efficient only on Windows. To do this enable Windows -> Preferences -> General -> Workspace -> Refresh using native hooks or polling.

Tried with: Eclipse 4.5 and Ubuntu 14.04