Eclipse/Nsight (7.0) and C++11 support - eclipse

TL;DR:
How can I persuade Nsight that I'm using C++11?
In other words, where do I set the relevant discovery options?
Building with -std=c++11 is working, even from within Eclipse. I'm talking about the Indexer having troubles with defines.
Longer version:
C++11 functions are marked as unresolved in the Nsight editor, because the __cplusplus define is 199711L, instead of something >= 201103L.
When I made the project, in Project Properties > Build > Discovery Options the Automate discovery of Path and Symbols option was checked for every language and every Build Configuration. There was a note on the bottom of the Properties windows that said that the discovery method is deprecated, so I unchecked it for every language and for every Build Configuration.
Now, under Project Properties > General > Preprocessor Include Paths, Macros etc. there are system provided paths and defines (more precisely, provided by the Providers). In the list I can see the problematic __cplusplus. I can redefine it under the CDT User Setting Entries and indeed it will be the new value after rebuilding the Index, but then whenever I click something in the editor I get an error:
An internal error occurred during: "Notifying selection listeners".
org.eclipse.cdt.internal.core.index.composite.CompositingNotImplementedError
That route is a dead end obviously. Another option is to define the new __cplusplus in Project Properties > General > Paths and Symbols under the Symbols tab. I can see the "wrong" __cplusplus there as well. Redefining it there gives me the same error as above, after rebuilding the Index, when clicking in the editor.
Also, what the hell is the CDT Managed Build Setting Entries Provider? I don't see any options for it. Where is it configured?
When I try to use the CDT GCC Built-in Compiler Settings Provider I see a field where I can input command line arguments, but putting -std=c++11 there has no effect, as that entry doesn't produce a __cplusplus define.
Offtopic:
In other news, C++11 support is great with the CUDA Toolkit 7.0, on the command line and in the makefiles. It saddens me greatly that nVidia settled on Eclipse. Whatever I did with it, I've only encountered trouble with Eclipse. Takes me a week just to set up the IDE for a project. I hate it so much.

I experienced a similar problem with the indexer when using the native compiler; however, the cross compiler worked correctly. When using the native compiler, __cplusplus was defined as 199711L even though the C++ dialect had been set to C++11 and the index rebuilt.
The indexer can pick up the C++11 settings by going to
Project Settings->C/C++ General->Preprocessor Include Paths, Macros etc.->Providers->CDT GCC Built-in Compiler Settings
and doing:
Uncheck Use global provider shared between projects.
Add -std=c++11 to Command to get compiler specs like so:
${COMMAND} -std=c++11 ${FLAGS} ...
__cplusplus should now be correctly set.

Related

Eclipse/CDT Type '__uint128_t' could not be resolved

I am working with c++ and it got type __uint128_t in the code. The code compiles fine on g++ (GCC) 4.8.3, but Eclipse/CDT always show error on "__uint128_t". The actual error message is "Type '__uint128_t' could not be resolved".
I tried several things already, including re-index, adding -std=c++11 to compiler's setting. Does anybody know how to make the error message disappear?
I am running Eclipse Luna Release (4.4.0) and CDT 8.4.0.
Eclipse will be able to correctly "parse" this type only if it's defined in some header of your toolchain. If it is a builtin type in compiler (just like "int", "char" and so on) - and I guess it is - then Eclipse would need to have special code to handle that type. So unless someone implements handling of this token in Eclipse, your only option is to disable this particular code analysis check for the files that use this type...
unchecking "Use global provider shared between projects" and adding -std=c++11 to the command line for the compiler specified in the "CDT GCC Built-in Compiler Settings", which can be found by opening project properties and going to "C/C++ General", "Preprocessor Include Paths", "Providers" tab.
then rebuilding the index: right-click the project, "Index", "Rebuild".
for detail please refer to the answer by davmac in post: Type 'uint32_t' could not be resolved
I had similar difficulties with Eclipse Oxygen.3 (with CDT 9.4 on Debian 7.10 64-bit, and GCC 4.7.2). I tried everything mentioned on StackOverflow as of March 30, 2018 to no avail.
Several headers in my project were being included by multiple source files. These headers were protected by #ifdef guards, but Eclipse CDT's CODAN code analysis system didn't seem to permit these guarded headers to apply to more than one .cpp source file. So numerous types and functions which returned those types were not recognized.
But after setting Window > Preferences > C/C++ > Indexer > Index all header variants, and then Rebuilding the index for the project, subsequent code analysis runs succeeded.
See a related answer from me if trying to utilize workspace-level settings.

Eclipse CDT indexer does not know C++11 containers

I configured a C++11 project in Eclipse CDT to use gcc-4.7. It is not the default compiler on my system, which does not support C++11. In order for compilation to work, I need to pass the flag -std=c++11 and also include the following header path: /usr/local/Cellar/gcc/4.7.2/gcc/include/c++/4.7.2
Whenever I use C++11 container types like std::unordered_set or std::unordered_map, the CDT indexer complains: Symbol unordered_set could not be resolved. How can I tell the indexer to resolve these symbols correctly?
This is how I have configured my indexer:
As far as I understand the settings, the indexer is supposed to use the compiler settings from the currently active build configuration. Compilation works fine, so why doesn't indexing, too?
Setting up **__GXX_EXPERIMENTAL_CXX0X__** does not help in my case (Jul 2014, Eclipse Kepler 20130919, Ubuntu 12.04).
To fix C++11 syntax highlighting go to:
Project Properties --> C/C++ General --> Paths and Symbols --> Symbols --> GNU C++
and overwrite the symbol (i.e. add new symbol):
__cplusplus
with value
201103L
UPDATED: If you use newer version of Eclispe (as of 2016) and still experience the same problem, try value (as pointed by jose.diego):
201402L
Make sure that indexer is enabled in Project settings (C/C++ general --> Indexer)
Then reindex (Project --> C/C++ Index --> Rebuild)
if the problem still persist reindex once again. It should work now.
I solved this problem recently after some lucky googling.
Click on your project and right-click->Properties
Select "C/C++ General -> Processor Include Paths, Macros etc..."
Select the "Providers" tab
Deselect everything except "CDT User Setting Entries" and "CDT GCC Built-in Compiler Settings"
Click on "CDT GCC Built-in Compiler Settings"
Deselect "Use global provider shared between projects"
Edit the box at the bottom labeled "Command to get compiler specs"
Insert into the command -std=c++11 so it looks something like this:
${COMMAND} -std=c++11 -E -P -v -dD "${INPUTS}"
Click Apply and Okay.
That worked for me. You probably need to re-index the project.
As described in this forum post:
http://www.eclipse.org/forums/index.php/mv/msg/282618/
right-click the project and go to "Properties" C/C++ General -> Paths
and Symbols -> Symbols -> GNU C++.
Click "Add..." and paste __GXX_EXPERIMENTAL_CXX0X__ into "Name" and
leave "Value" blank. Hit Apply, do whatever it asks you to do, then
hit OK.
Or go to:
C/C++ Build->Discovery Options->GCC C++ Compiler
add your flags to the Compiler invocation arguments. like -std=c++11 -m32
Clear discovered entrys now: click on Clear
rebuild the project
After that ALL symbols will be updated with correct values and the indexer should work as intended
The workaround for me, with a project that uses an external builder, was to define the symbol:
__cplusplus
with the value:
201403
in the project's: Paths and Symbols -> Symbols/GNU C++.
This worked in eclipse Kepler CDT Version: 8.3.0.201402142303.
See this guide:
C/C++ Build->Settings->GCC C++ Compiler->Dialect
Choose "ISO C++11 (-std=c++0x)" in "language standard"
Apply and OK
Rebuild the project and it works:)
The follows works in Eclipse C/C++ Oxygen.2 with gcc-5.5.0
Eclipse Properties->C/C++ Build->Settings->GCC C++ Compiler->Dialect->Other dialect flags: -std=c++17
Don't pick up anything in the Language standard dropdown list.
The following configuration helps me to fix the issue indicated in the original question.
Environment:
Eclipse(Oxygen.3a Release (4.7.3a)), Cygwin64.
In case you have a different version of Cygwin, you can find similar directories as follows.
Step 1: Make sure you have the following two directories:
C:\cygwin64\lib\gcc\x86_64-pc-cygwin\7.4.0\include
C:\cygwin64\lib\gcc\x86_64-pc-cygwin\7.4.0\include\c++
If you don't see the above two directories, please launch your Cygwin setup program and install gcc-core, gcc-g++ and libgcc1.
Step 2: Copy the directory C:\cygwin64\lib\gcc\x86_64-pc-cygwin\7.4.0\include to C:\cygwin64\usr if you don't see above two include directories.
Step 3: Go to Project Property->C/C++ General->Paths and Symbols
Make sure you can see the following two paths are listed
C:\cygwin64\usr\include
C:\cygwin64\usr\include\c++
Step 4: Property->C/C++ Build/Settings/ Choose Cygwin PE Parser
Step 5: Property->C/C++ Build/Tool Chain Editor Choose Cygwin GCC
Step 6: Property->C/C++ General/Indexer Choose Enable indexer
Step 7: Project->C/C++ Index->Rebuild
Now your eclipse should be able to see the C++11 types.

Include directory specification not working on Eclipse Juno

I'm using the latest 32bit Eclipse Juno. I've seen many posts about folder inclusion, but none worked for me.
The problem:
#include<iostream>
#include<osgDB/ReadFile>
#include<osgViewer/Viewer>
The compiler (GCC) reports "unresolved inclusion <iostream>" and corresponding unresolved inclusion errors for ReadFile and Viewer.
What I tried, to solve it:
In Project properties > C/C++ General > Paths and symbols > Includes. I added /usr/include/c++/4.4.4/ for all configurations and all languages. This automatically caused the values in C/C++ Build > Settings > GCC C compiler and GCC C++ compiler's includes > include paths to contain the same values.
The unresolved inclusion error persisted.
Then I tried adding iostream to the include files section below the include paths section. Still no use. Even tried closing and re-opening eclipse after the changes. Still no use.
The only other option was to specify the absolute path which worked:
#include "/home/nav/osg/osg/include/osgDB/ReadFile"
#include "/home/nav/osg/osg/include/osgViewer/Viewer"
#include "/usr/include/c++/4.4.4/iostream"
But isn't the right way to do it. Could anyone help with specifying the include paths the correct way?
I had similar problem and it was caused by the indexer not using the correct build configuration. By default, the indexer was set to use global settings, rather than project specific ones (I'm using Nsight, the version of Eclipse by Nvidia).
Go to
Project properties -> General -> Indexer
Tick
Enable project specific settings
Select
Use active build configuration
This might be irrelevant for you. I'm compiling the same project on multiple machines/OS's and hence have different include paths for each build configuration.

Eclipse Juno's "Preprocessor Include Paths, Macros etc." symbol scanner for CDT

So there has been an overhaul of the scanner discovery as worked on here:
https://bugs.eclipse.org/bugs/show_bug.cgi?id=290631
http://dev.eclipse.org/mhonarc/lists/cdt-dev/msg24345.html
However, I can't find any information on how to use it. I upgraded from Helios to Juno recently and now I have 8000 "Semantic Errors" and a ton of unresolved includes. However, I can't figure out how to use this new feature. I don't think there's any documentation yet, either.
I think the intent is it will scan your project and automatically discover macros and include directories in order to aid in symbol resolution and project navigation.
I'll keep working on it and update this question if I ever figure it out.
Figured it out.
Used this as a guide: https://developer.mozilla.org/en/Eclipse_CDT
In the project properties, "C/C++ Build", I replaced the default build command with my build command. I had to remove a -s switch (silent switch) so the output parser could grab all the paths and macros from the compiler commands. Pointed the "build directory" to the directory with my makefile.
Under "C/C++ General" > "Preprocessor Include Paths, Macros etc." > "Providers" I selected CDT User Setting Entries and CDT GCC Build Output Parser. I then had to change the compiler command pattern to match my gcc cross compiler. To do that, I just changed "gcc" to "arm-elf-gcc".
After a full build (do not use multi-core builds for the first indexing), right click your project, click 'index' and 'rebuild'. After this, the output parser populated the indexes correctly and they showed up under "C/C++ General" > "Preprocessor Include Paths, Macros etc." > "Entries"

Eclipse CDT shows semantic errors, but compilation is ok

I have installed Eclipse Indigo for C/C++ Linux developers on Ubuntu 10.04 x86.
When I use common predefined macro __BASE_FILE__ Eclipse says Symbol '__BASE_FILE__' could not be resolved, but compilation is OK. I have to use it so often in my code and Eclipse fills my screen with red lines and bug icons :)
How can I fix this?
Not sure if this addresses your specific problem, but I also had semantic errors. They just came out of the blue after having a working project.
Anyway, I fixed it with a single option in workspace settings by setting:
"Build configuration for indexer: Use active build configuration"
The other option was "Use the build configuration specified in the project's indexer settings" and this is the one that wasn't working. I think it may have been corrupted after an eclipse crash.
Window -> Preferences -> C/C++ -> Code Analysis -> Syntax and Semantic Errors: OFF
This won't solve the cause of the problem but at least will stop the false errors from being shown.
The simplest solution is to reset the indexer:
Window / Preferences / C/C++ / Indexer.
uncheck "Enable indexer" ->>OK
rebuild all, may show lots of errors
check "Enable indexer" ->>OK
rebuild all
This error can be produced by forced closing of eclipse by power failure.
You need to rebuild the index of your project.
Right-click on the project, then Index->Rebuild.
Deleting the .metadata folder , and then Import project .
This way is OK!
Updated:
You have to add proper paths to Project->Propoerties->C/C++ General->Paths and Symbols. If it does not help, you can configure Eclipse Code Analyser (which generates the 'errors') in Project->Properties->C/C++ General->Code Analysis. Under the error description you have problem with, try Customize Selected->Scope->Exclusion Patterns.
IMO the correct solution is to define the symbol in Project -> Properties->C/C++ General -> Paths and Symbols -> Symbols tab. Since you can assume the symbol will always be supplied by the compiler, you just tell Eclipse to consider it defined.
I had the same problem just recently, where Eclipse complained about undefined macro, that i always supply using -D<MACRO_NAME> compiler option.
I think it has something to do with the workspace/.metadata.
I had the problem of semantic errors reported but Hello World compiles and runs.
I deleted the project, created another one, same error reporting. Reinstalled CDT, same thing. Deleted the workspace, shut down Eclipse, restarted, created new hello world, same thing. Deleted the workspace again, shut down Eclipse again, this time noticed that Eclipse had recreated the workspace folder during shutdown when it couldn't find it. Deleted the workspace with Eclipse shut down. Restarted Eclipse, created HW project, errors show for about a second and then gone. Deleted project, created another one, errors show for a sec, then poof.
If you actually had projects in your workspace (mine was a clean install), I bet that you could just delete the .metadata folder within the workspace, and it would fix it.
I personally agree with compostus' answer.
It's good to solve the real problem that eclipse's code analyzer have.
But when I try this steps:
define the symbol in Project -> Properties->C/C++ General -> Paths and Symbols
I don't find symbol tab or any place to add a symbol. what I want to do is putting macros like -DANDROID or #define ANDROID 1 to eclipse so that the code analyzer can find this definition.
I'm under Mac OSX mountain lion.
adding as another answer, hopefully this will help someone.
I have a ~simple workspace (1 c++ shared-object (linux's version of a DLL, 3 c++ executables, and a pydev python project)
I checked out all the code to a new machine, and it builds fine but had numerous 'semantic errors' on std-c and std-C++ code and includes.. I went through all the discovery / indexer setting to no avail.
==> deleting the entire .metadata folder fixed this.
Since i had nothing non-trivial set up in the workspace (all in the project files / makefiles), eclipse happily created a fresh workspace, and i simply had to do a file->import-> existing projects
If on Ubuntu, go to Window > Preferences > In Search box type "Indexer" > Select Indexer in left column.
Under heading "Indexer Options" tick the following options (all but those involving the skipping of files):
Index files source files not included in project
Index unused Headers Index all header variants
Index source and header files openend in editor
Allow heuristic resolution of includes
Under heading "Indexing Strategy" tick both options which are:
Automatically update the index
Update index immediately after every file-save
Under heading "Build Configuration for the indexer" select the following option:
User active build configuration
try this:
Preferences --> c/c++ --> Indexer --> Index all header variants
check this option.
This is a file indexing issue.
Solution - Right click on the project, Index->Freshen all files.
(Applies to Eclipse CDT.Oxygen)
In my case, I eventually discovered that the indexer was having problems because a colleague had “helpfully” duplicated a whole load of declarations in two header files that were only included together in a small subset of C files in the project. Removing the duplications (and making one header include the other) allowed the indexer to function correctly again.
It was particularly a problem with duplicated enumerations, for some reason. I do not know why this is so.
I used #pragma once in my code. This configuration caused me to have the problem:
---fileA.h---
#pragma once
#define MYMACRO(X) func(X)
---fileB.h---
#include "fileA.h"
---fileB.cpp---
#include "fileB.h"
MYMACRO(5) <---- warning here
I replaced #pragma once with #ifndef #define HEADER_FILE_H #endif, and that fixed the problem.
Not sure if this works for the OPs issue, but I had semantic errors in eclipse Luna and was able to resolve them by following instructions in this thread: Eclipse shows unresolved inclusion but it compiles
The compiler finds the header, but Eclipse not.
You could help Eclipse and set the path to the header files under:
Project -> Properties -> C/C++ Build -> Settings -> Compiler ->
Includes
In my situation, eclipse had determined one of my include directories, but did not determine that there were sub-include directories within it.
I had a similar issue but my compile was fine but Eclipse showed errors on lines that used a #define from another include file. I fixed by checking "Index all header variants". I think the classis #ifndef FILENAME in include file was process multiple times in Indexer and so 2nd time the FILENAME was defined so all #defines in .h file were not "seen" by the preprocessor. Go to Window | Preferences | C/C++ | Indexer.
I have the same problem. Compiler preprocesses ok, but static analyzer doesn't. In my source file:
#define PLATFORM_INC_FILES
#include <platform.h>
int coflags=O_BINARY; // Undefined symbol
In platform.h (an OS dependent header to help creating portable code):
#ifdef PLATFORM_INC_FILES
#include <stdio.h>
...
It looks like static analyzer doesn't take the .c #define statements into account when preprocessing included headers. By defining it at the symbols dialog, errors dissapear, but that is a project scope symbol definition, resulting in every source to include every system header in my case.
Hope it gets fixed soon...
Using Eclipse Mars and MinGW on MSIS2.
The problem occurs this way: I insert a new variable name into the code somewhere e.g. "newone" in this example:
int a;
foo()
{
a=17;
newone=23;
}
The file is saved (so the indexer is reindexing).
Then I added the definition:
int a, newone;
foo1()
{
newone=0;
}
foo()
{
a=17;
newone=23;
}
The indexer will still shows the error at the line " newone=23;" but not at the other lines of code containing "newone".
Solution: first define your variables, then use it.
M.
In the past, I would define the ANDROID symbol in:
Project -> Properties->C/C++ General -> Paths and Symbols -> #Symbols tab
However, the latest version of Eclipse no longer has a # Symbols there, or anywhere else.
It seems there is no longer any way of defining symbols in Eclipse.
Eclipse has so many bugs and problems.
I finally gave up and switched to using Gedit and the terminal to compile.