4

I use Eigen C++ matrix library with Eclipse on ubuntu. Here is the simple code:

#include <iostream>
#include <eigen3/Eigen/Core>
using namespace Eigen;
using namespace std;

int main() {
  VectorXcd spec(5);
  spec(4) = std::complex<double>(1, 2);
  cout << spec(4).imag() << "\n";
  return 0;
}

It runs ok, but eclipse indicates a semantic error called "Method 'imag' could not be resolved". Phenomenons as this also occur in my own project with Eigen. I use several 3rd party libraries, but such errors only relate to Eigen. However, if I switch to visual studio 2013 under windows, everything is ok, and I can also come into the implementation of the relevant code in Eigen library.

I guess it is parsing problem for template library.

Cœur
  • 37,241
  • 25
  • 195
  • 267
yan
  • 41
  • 3

1 Answers1

2

Error highlighting in Eclipse is not the output of a compiler. Often, Eclipse doesn't even know where header files are located. There are different options to tell Eclipse where include files are:

  1. You can add /usr/include/eigen3 the list of C++ includes. (Right-click on project, properties, C/C++ general, paths and symbols, all configurations, includes, C++, add...). This is tedious and has to be done for all configurations and projects.

  2. Eclipse can sometimes find include paths automatically when they appear in the compiler logs. For instance, if you use CMake as a generator and build within Eclipse, setting more verbose compile commands will forward these paths to Eclipse. For this, add set(CMAKE_VERBOSE_MAKEFILE ON) to your top-level CMakeLists.txt. Make clean, re-compile, re-run indexing in the context menu of your Eclipse project.

  3. Alternatively, you can set up a different build process where a build system generates your Eclipse project. CMake, for instance, can create Eclipse projects that uses the Ninja build system. The project then has the correct settings to do syntax highlighting. https://cmake.org/cmake/help/v2.8.9/cmake.html#gen:EclipseCDT4-Ninja

SpamBot
  • 1,438
  • 11
  • 28
  • What has syntax highlightning to do with the question? – colidyre Oct 07 '15 at 11:45
  • You're right, it is about Eclipse highlighting errors and warnings, not syntax. If the problem is not limited to Eigen, perhaps it is because of Eclipse not parsing C++11 http://stackoverflow.com/a/9135135/2079934 – SpamBot Oct 07 '15 at 14:21