How do you configure GCC in Eclipse to use C99? - eclipse

I'm working on a small C project in Eclipse; I just installed Eclipse from the Ubuntu Software Center and added C/C++ Language Support. I can build, run, and debug simple C programs fine.
But I'm using some C99 features now, and Eclipse complains, saying "'for' loop initial declarations are only allowed in C99 mode".
I thought you'd set C99 mode for GCC in the makefile, but the makefile is auto-generated by Eclipse so any changes I make would be overwritten, but I don't see anywhere to put GCC compiler options anywhere in Eclipse's preferences nor my Project Properties windows.
So where do I define C99 mode?

Go into project properties. Search for C/C++Build -> Settings. In the Tool Settings tab search for GCC C compiler and then Miscellaneous. In other flags text box add the -std=c99. It should work fine.

Related

How to enable c++11 in eclipse Luna?

I have eclipse Luna.I want to use auto variable in my project and for that i need to enable c++11 in eclipse.I have followed this answer Eclipse CDT C++11/C++0x support
But in my project's property, there are no option like c/c++ Build. There are only one option named c/c++ General.
So using c/c++ general how can i enable c++11 in my eclipse.Please anybody know the solution then mention steps.thanks.
For Eclipse Luna, go to Project > Properties > C/C++ Build > Settings > Tools Settings > Cross G++ Compiler (or whichever compiler setting you're using) and choose "ISO C++1y (-std=c++1y)" or "ISO C++11 (-std=c++0x)". Or instead, in "Other dialect flags", you can put std=c++11, or std=c++14, but if you do it this way you'll probably have to take an additional step not covered here so the Eclipse editor will produce error flagging for the correct C++ version in the editor.

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

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.

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.

How to ignore assert(false) in release mode?

My program built in release mode fails on assertions.
How can I setup eclipse to generate a binary which doesn't compute assert() calls?
The solution is simple:
Right click on project, select Properties. Go under C/C++ Build, Settings. Select the Release configuration, then GCC C++ Compiler, Preprocessor. Under Defined symbols (-D) add NDEBUG. This worked for me.

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.