Eclipse can't fully parse Eigen C++ library, but it compiles ok - c++

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.

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:
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.
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.
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

Related

Eclipse CDT indexer different results for C file than C++ file

I'm using Eclipse 2018-12 with latest CDT. Getting odd indexing problems with the Editor. Given the below. If the source file has a ".c" extension the indexer complains that type "bool" and "false" cannot be resolved. If the file has a "*.cpp" extension the type is resolved.
In both cases, the project will build and can be debugged.
Not sure if it matters, but I'm using CMake 3.13 to generate Eclipse Project files, although I have tried to manually adjust project settings to no avail.
#include <stdbool.h>
void main(void)
{
bool success = false;
}
I have a C Project, but my unit testing is using GTest and are the only .cpp files in the project. All .c files exhibit this behavior.
Found a similar post in an Eclipse forum. Consensus was this might be a Bug in the indexer/editor code.
However there was a workaround solution. It you have a Project with both .c and .cpp files in the project Properties -> C/C++ General -> Language Mappings, add a mapping for "C Source File" to the "GNU C++" Language.
Since my build files are being generated by CMake I don't believe this will impact the way Eclipse Builds/Debugs my code.
I agree that this is a bug in Eclipse CDT, which I've filed in its bug tracker.

Eclipse not finding std c++ libraries

I have a Windows8 machine with mingw installed in c:\mingw
Eclipse does successfully compile programs, but it considers lines to contain errors that are fine when compiled. Eclipse is not finding the libraries itself.
When I first build a project in eclipse with the CDT components install, it shows errors on every #include and every line using an object.
Example:
#include <iostream>
using namespace std;
int main() {
cout << "hello\n";
}
The above code shows errors on the include, the using and the cout << line.
I can get rid of the errors by clicking:
project->properties C++/General Preprocessor Include
Then on the providers tab, I can check off "CDT Build output parser" and fix the mistakes as described by the first answer below, which I am upchecking. But this only works for the project. I have to do this every time. How can I get eclipse to simply accept standard C++ EVERY TIME I build a new project without reconfiguring each project?
I have been able to stop errors on the includes by going into project settings and adding the directories:
c:/bin/mingw/lib/gcc/include
...
That leaves the errors on lines using the objects.
#include <iostream>
#include <string>
#include <regex>
using namespace std;
int main() {
string s = "this is a test.";
regex e("est");
smatch m;
The line with regex still shows an error: "type regex could not be resolved"
even though the code compiles and the regex include is recognized.
Additionally, on a different machine running windows 8.1 with Mingw installed, eclipse will not debug. Is there some document on how to connect Eclipse CDT to the library?
While you obviously successfully compile the code with gcc from within Eclipse, Eclipse has its own built-in C++ parser and you need to separately let it know that you are using C++11.
Add the -std=c++11 option to the CDT GCC Builtin Compiler Settings under Project propierties -> C/C++ General -> Preprocessor Include Paths, the compiler specs should look similar to this:
${COMMAND} -E -P -v -dD ${INPUTS} -std=c++11
UPDATE. Please read Setting Up Include Paths and Macros for C/C++ Indexer to understand how CDT automatic discovery of include paths and preprocessor symbols (aka Scanner Discovery) for supported tool chains is applicable to you.
The gist is that the CDT uses the Language Settings Providers to find include paths and preprocessor symbols. And Language Settings Providers can be configured on project properties page "Preprocessor Include Paths, Macros, etc."
Once you have proper settings you can make them a template workspace and just copy the template workspace over for your new projects, or alternatively have a script that will set up just the relevant settings. Also see: Setting preferences for all Eclipse workspaces.
I have had the same problem. Eclipse underlined like an error a regex keyword, but project was built without errors. I chose a Language Dialect as "ISO C++1y (-std=c++1y)" in Properties->C/C++ Build->GCC C++ Compiler->Dialect Language Standart
Been a while, but adding in case someone else finds this answer as I did.
I had what appeared to be this issue but it turned out that while I had installed MinGW, eclipse still expected me to have installed cygwin. Go to project properties > C/C++ Build > Tool Chain Editor > Current Toolchain and select the appropriate option.
Not sure why it defaults the setting to a toolchain it can't find.

How to solve Unresolved inclusion: <iostream> in eclipse?

I built a simple program in eclipse:
#include <iostream>
using namespace std;
int main()
{
cout << "TEST" << endl;
return 0;
}
It worked in Visual Studio and CodeBlocks, but eclipse is acting weird. it says:
Unresolved inclusion: <iostream>
I read here:
C++ - Unresolved inclusion: <iostream>
and here: Unresolved <iostream> in Eclipse, Ubuntu
and neither of them worked.
Here are screenshots of project properties:
edit:
I downloaded MinGW and now i have this under Settings:
How should i proceed?
Maybe now i don't need #include <iostream> because it's now included in the project?
I found iostream under Includes.
So i tried deleting #include <iostream>, but when i try to run the program i get:
Launch Failed. Binary not found. error:
Thanks
edit:
Seems like if i compile in some other program (say CodeBlocks) and create the exe file, then eclipse can run it. But it can't build its own exe.
Why?
This answer did not help me either. My issue was solved with the following steps:
You might try changing your source files from *.c to *.cpp. This will provoke gcc to think of the files as C++ and search the proper paths. Might need to make small modifications to the Makefile as well, like on the OBJ: line. Instead of:
OBJS = YourFile.o
try
OBJS = YourFile.cpp
I've searched for a few hours and tried a lot solutions.
Envirment: windows, Eclipse IDE for C/C++ Developers
Version: Kepler Service Release 2
CDT: 8.3.0
Following steps works for me:
make sure the envirement is clear. => I suggest delete the eclipse and unzip it again from your orginal download.
make sure the workspace is clear. => Delete .metadata folder in your workspace folder.
use valid MinGW. => the one using download tool is slow and I'm not sure which one to select. I suggest download MinGWStudio from http://vaultec.mbnet.fi/mingwstudio.php
This is a IDE tool like eclipse contains a downloaded unzip MinGW. Make sure you download the one plus MinGW compiler which is about 20M. You can use this studio if you want or copy the MinGW folder to C:/ if you still prefer eclipse. Copy /MinGW inside /MinGWStudio to C:/.
close your eclipse and reopen it, create a new project, you should able to see MinGW section for new project option, and it will auto map g++, gcc and include files under C:/MinGW folder. Just make sure you copy MinGW folder from MinGWStudio to the root of C:/.
You will able to see your include after these steps.
includes_screen_cast
right click your project click properties goto C/C++ Build > settings click on Misc. under GCC C++ Compiler and the other flags code should have this after it -std=c++11 then go to Misc. under GCC C Compiler and add this to the other flags code -std=gnu11 apply save your project build your project and it should work

How to start a CodeBlocks project from external code and Makefile?

I have C++ code that depends on boost and other libraries, and therefore this code has a makefile that invokes boost.
I am now trying to start developing this code in CodeBlocks in linux, so in order to do that I have two basic questions:
(1) How can I import the code into CodeBlocks as a CodeBlocks new project? This seems to be a good rec: http://www.programmingforums.org/thread44976.html
(2) How do I invoke the makefile with CodeBlocks instead of CodeBlocks trying to compile the code (which would fail since CodeBlocks do not know that it needs to invoke boost)?
How can I import the code into codeblocks as a codeblocks new project?
File > New > Project > Empty project
Create the project, then:
right click on the project name on the "Projects" pane;
add files recursively.
I recommend that you create Code::Blocks project new project at the top-level of your source (and not e.g. in a dedicated ~/codeblocks directory), or else it will show long file paths.
How do I invoke the makefile with codeblocks instead of codeblocks trying to compile the code (which would fail since codeblocks do not know that it needs to invoke boost)?
Asked at: Is it possible to use an existing Makefile to build a project in Code::Blocks?. For quick reference, the solution is to go to Project > Properties and toggle on the option This is a custom Makefile. Further options can be specified from the same window.
Most projects can be compiled without a makefile, so just include files, and if you need an extra library include that in a project. If your project uses header-only boost libraries and you have packet installed libboost-dev (this is on my Debian) then it is included automatically. Else just use the proper library name in settings (I can't remember if you need to append l to the name).

Error check in Eclipse CDT using Makefiles

I'm using eclipse to develop my project, which bases on my custom makefile system. I have to use custom Makefile project because I want to tevelop LLVM porject pased on the LLVM makefile system, see: http://llvm.org/docs/Projects.html.
I created an "empty makefile" project in eclipse, I'v chosen the build location (Project->Properties->C/C++ Build->Build Location) and added every needed library sources (Project->Properties->C/C++ General->Paths and sources).
The project build and executes like it should. The problem is that a lot of lines is underscored with red colour as errors. This is obvious because eclipse chcecks for erros executing gcc and it does not executes it unless I'm using Makefiles (or maybe I am wrong ...).
Anyway - is there any way to check for syntax (and other types of) errors while using eclipse with makefiles?
Check out this question, or google "eclipse unresolved symbols". You need to add the paths of your includes to your project settings, so Eclipse editor/indexer can find them.
The question in the link is for unresolved includes, but it also applies to all unresolved symbols.