Eclipse cannot fully parse the Eigen C ++ library, but it compiles fine
I am using Eigen C ++ matrix library with Eclipse on ubuntu. Here's a 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 works fine, but eclipse indicates that a semantic error called “method” cannot be resolved. ”Phenomena like this also happens in my own project with Eigen. I use several third party libraries, but such errors only apply to Eigen. However, if I switch to visual studio 2013 under windows, everything is fine and I can also start implementing the appropriate code in the Eigen library.
I am guessing this is a template library parsing problem.
source to share
Error highlighting in Eclipse is not a compiler output. Often times Eclipse doesn't even know where the header files are. There are various options to tell Eclipse where to include files:
-
You can add
/usr/include/eigen3
a C ++ list. (Right click on project, properties, C / C ++ general, paths and symbols, all configurations including, C ++, add ...). This is tedious and must be done for all configurations and projects. -
Eclipse can sometimes find include paths automatically when they appear in the compiler logs. For example, if you use CMake as a generator and build inside Eclipse, setting more verbose compilation commands will redirect those paths to Eclipse. To do this, add
set(CMAKE_VERBOSE_MAKEFILE ON)
to the top levelCMakeLists.txt
. Clean up, recompile, rerun indexing from the context menu of your Eclipse project. -
Alternatively, you can set up a different build process when the build system generates your Eclipse project. For example, CMake can create Eclipse projects that use the Ninja build system . The project then has the correct settings for syntax highlighting. https://cmake.org/cmake/help/v2.8.9/cmake.html#gen:EclipseCDT4-Ninja
source to share