Eclipse is highlighting bool, true, and false as could not be resolved.
Note that the application builds fine.
How to fix this?
My Setup
Eclipse Version 2021-06 (4.20.0) Build 20210612-2011
gcc version 4.8.5
What I've tried
I've found posts that say to change the following:
First
Properties -> C/C++ Build -> Settings -> Tool Settings -> GCC C++
Compiler -> Dialect to -std=c++14 or whatever.
I can't find this option in my properties editor
Second
Select Window->Properties -> C/C++ General -> Preprocessor Include Paths, Marcos etc. -> Providers Tab
I did this and added -std=c99
no effect, or maybe the wrong std?
What I think is happening here is that the version that Eclipse is providing linting for is different than the one which is being used for building the program. Sync up the properties of the makefile with Eclipse.
You can find build properties at Project -> Properties -> Build Settings. Make sure the build command, flags, C dialect, etc are the same as the one in the makefile. Look at the CFLAGS variable of the makefile and it'll show the properties, like C standard, optimization(for debug mode, make sure there's none, use -g no matter what the makefile says because it's probably for release.) and then select the same options in Eclipse.
Most likely, the standard of C in the makefile is C99 but in Eclipse, it's C89 or something like that, in which case, simply modifying the standard will work.
If the makefile uses, g++ but is pure C, the project either uses a bit of C++, so port the project to a C++ project. If it's pure C but uses g++, you'll have to also make it a C++ project and deal with life or if you feel able enough to change the makefile, do so and use gcc. This problem is the most likely.
I don't even fully understand how Eclipse build works and that's why I migrated to Visual Studio Code, there might be some issues with this, feel free to ask for clarification by commenting. AND MAKE SURE YOU HAVE #include <stdbool.h> on each file that uses bools.
Related
I use Eclipse CDT Mars.2 (and Neon RC), on Linux. My distribution's default C++ compiler is GCC 5.3.1, but for some of my work I use GCC 4.9.3. I would like everything regarding my project to use GCC 4.9.3: The tool discovery, the C++ standard library, the include file paths, the indexer, the preprocessing - all of it.
What's the right way to do this? It seems Eclipse has rather byzantine "providers" and "toolchains" configurations and I do not want to make settings I won't be able to undo later...
Note:
I did try to replace ${COMMAND} with /usr/bin/g++-4.9 in some of the Preprocessor Includes etc. provider settings, and this did result in 4.9.3-related include files being discovered, but my indexer didn't like that and all of the std::stuff showed up red and unresolved. Then I tried looking for where I set the compiler version used for indexing but I couldn't find that.
There are two possible answers, depending on whether you are doing "Standard Make" or "Mangaged Make". Standard Make means you are writing your own Makefiles and managing all that yourself. Managed Make means you are letting CDT create the Makefiles and manage them.
Standard Make
For standard make, everything is controlled by what the scanner discovers. The scanner handles finding all the system include files that are part of your project, and those are fed into the indexer to resolve symbols and also allows things like header file navigation.
To change the compiler that is used, you need replace ${COMMAND} with your compiler of choice. It is up to you (as the user) to ensure that this command matches what you are using in your Makefile.
To change the ${COMMAND}:
Open Project Properties (by right-clicking on the project)
Select C/C++ General -> Preprocessor Include Paths, Macros, etc in the tree.
Select Providers tab
Select CDT GCC Built-in Compiler Settings from the list
Replace the ${COMMAND} in Command to get compiler specs: to your desired g++ executable.
Here is a screenshot to help:
To see this in action, here are some screenshots with and without the change described. On my machine I have /usr/bin/g++ which is version 5.3 and /usr/bin/g++-4.7 which is version 4.7.
With default g++
With overridden g++ to version 4
Use Environment manage
The problem with the above is that you need to coordinate g++ between your Makefile and the build settings. One solution to this is to use the C/C++ Build Environment settings to define CXX as the compiler to use. Set the CXX environment variable in the project settings (Project Properties -> C/C++ Build -> Environment) or global preferences (Preferences -> C/C++ -> Build -> Environment).
Then replace ${COMMAND} with ${CXX}.
Here is a screenshot that demonstrates what I described:
Managed Make
If, instead, you are using Managed Make, you need to override the build settings for the individual tools. These settings then feed into the Preprocessor Include Paths, Macros, etc. settings as used directly by Standard Make.
To change the build settings, you need to override the command used for the compiler in a few places, once for each type of tool. Start in Project Properties -> C/C++ Build -> Settings and then edit each of these:
GCC C++ Compiler -> Normally set to g++
GCC C Compiler -> Normally set to gcc
GCC C++ Linker -> Normally set to g++
Here is a screenshot to demonstrate:
I need to use the C++ osmium library and I program using Eclipse cdt.
To be sure my system is well configured, I managed to compile and link few of the examples by hand using the installed gcc 4.8.2 that is enough according to osmium documentation.
Osmium uses C++11 and it seems my Eclipse has a problem understanding it.
I followed the instruction in the not-really-duplicate answer, but does not help.
I added -std=c++11 to the project properties under C++ Build -> Settings -> C++ compiler -> Miscellaneous and under C++ Build -> Discovery Options.
I also tried adding the macro __GXX_EXPERIMENTAL_CXX0X__.
Strangely in my main file it seems the C++11 features are working, for example I can write
for (auto a : {1,2,3,4,5}) {}
but the osmium directory I copied in the project instead results filled of errors. It is not a missing include directory since the lines #include <osmium/so/and/so> show no errors.
Similarly, std::move even after including utility, gives the cannot be resolved error.
However, I noticed that the code actually builds, even if Eclipse shows multiple errors around the code.
I stuck, what can I do to set up Eclipse?
I'm trying to configure Intellij to create C/C++ projects. The plugin was installed successfully but when I go to create a new project, I have to setup a Cpp SDK. Is This a path to GCC home or similar (I try it but doesn't works)? How can I perform this configuration?
Here is detailed about the configuration:
Install the plugin. There will appear no special project type for C/C++ projects. Just take/create any Java project, and the plugin will process all *.c/*.cc/*.cpp source files from the project source roots.
Then you need to specify the C/C++ dialect. Open Settings->IDE Settings->C/C++. There are three options, which can be used for tuning:
Compiler selector — you may choose between GCC and MS VC dialects
Use C dialect — this option makes the compiler to treat the sources like C, not CPP files.
GCC executable name — gcc is used if this field is left blank. This option is important for GCC configuration autodetection.
To parse the files you also need to specify include paths for your C/C++ environment. Currently, the plugin can automatically detect GCC include paths, in case of other compilers you need to specify the include paths by yourself. Additional include files can be specified for each project separately. Automatic gcc include paths detection works only if your compiler presents in path. If it does not (or if you want to use include-paths of a non-default compiler), then you should specify the name (full name, if necessary) of gcc executable in GCC executable name field.
UPDATE: I would suggest you to try JetBrain's CLion - The intelligent cross-platform C/C++ IDE for cross platform development.
If you are using Visual Studio then use Resharper C++. ReSharper C++ makes Microsoft Visual Studio a much better IDE with refactorings, navigation, code inspections, quick-fixes, code generation and more productivity features for C++ development.
I need to set the compiler options in my makefile project in eclipse.
I followed this instruction:
http://www.eclipse.org/forums/index.php/mv/msg/282618/787571/
where the last part states:
Obviously make sure your rule includes "-std=c++0x" as a compiler option.
But there are no "tool-settings" in the project properties of my makefile project.
Is there another way to set the compiler options for a makefile project?
Thanks.
If it's a makefile project, then the makefile specifies how to build it, not the Eclipse settings.
Exactly how to specify the compiler options depends on how the makefile is written, but typically they are in a variable called CXXFLAGS, since that's what the default C++ build rule uses.
Unless you need to support outdated compilers, I suggest specifying c++11 rather than c++0x.
I am using Netbeans 7.2.1 for Ubuntu Quantal Quetzal to program C++. Unfortunately, its code assistance doesn't recognize features of C++11 even after I specified the C++ version to be C++11 and then re-parsed my code.
My code, which replies on C++11 features such as unordered_map are compiling and running just fine though.
Hence, I hypothesized that I might not be telling code assistance to seek the right directories for various headers. Hence, I went to Tools -> Options -> c/C++ and added some more directories in the "Include Directories" section (for 4.7.2):
Strangely, next to the directories I just added are little keys. What do these little keys mean?
Fyi, code assistance still does not recognize C++11 features.
They are almost certainly the include paths built into the compiler. The code assistant needs to know them or it will miss vital information needed for understanding the other headers and completions but because they are built into the compiler they cannot be changed by the user so they have a key next to them to show they cannot be changed
This is however an educated guess based on my work in other C++ IDEs and knowledge of how compilers handle this stuff
Assuming you are using gcc you can find a list of the built in include directories with echo | g++ -Wp,-v -x c++ - -fsyntax-only and check if they match up.