How to ignore assert(false) in release mode? - eclipse

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.

Related

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

eclipse for android c source code - how to resolve compiler head file?

I am now using eclipse to develop driver and daemon on android platform in C code with a pandaboard, and I want to use eclipse plus CDT as an edit and browse tool.
I have imported android-source code into eclipse as a makefile project, and processing with indexer.
My problem is, since there are lots of head files for different archetecture(x86, arm, etc) like etc, etc. Eclipse reports an error like "unresolved inclusion xxx" because there are too much candidates of those files. Can eclipse analysis makefile and select the correct path like compiler if I specify a variable or identifier to notify eclipse just like a makefile option?
Can anyone help me, please?
Thanks,
-Yunfei
For your driver work checkout:
http://wiki.eclipse.org/HowTo_use_the_CDT_to_navigate_Linux_kernel_source
In general when working with a Makefile project you need to give Eclipse a hand so it knows where to find the includes and which preprocessor symbols are defined.
Right click on your project. Select properties -> C/C++ General -> Path and symbols.
Add the most important include paths and the indexer results will become much better.

CDT Eclipse: Undefined Variables even the .h file included

I'm newbie on using CDT and Eclipse. I want to make an STM32F10XX (Cortex-M3) aplication. I have a problem when I'm compiling the code, it always show undefined variables error. I used Eclipse setting as shown on Setting up Eclipse and Code Sourcery lite for STM32 Discovery Development.
But I make my own startup code, just using stm32_flash.ld and startup_stm32f10x_md_vl.S.
Is there any included or project setting missed?
discussionstackoverflowquestion
Try using the gnu99 flavor of C. Found in project Properties > C/C++ Build > Settings. MCU C Compiler Miscellaneous.
I'm guessing it is complaining about an untagged union. But this is a guess...

How do you configure GCC in Eclipse to use C99?

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.