What does the lock next to the include directory mean? - c++

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.

Related

Xcode (Version 9.2 (9C40b)): C++ Semantic and linker issues when trying to include boost

I am currently working on a masters project and I am desperately trying to compile some C++ code on my mac (macOS High Sierra 10.13.3 using Xcode) so I can develop the program at home. The Program is a set of files used for performing integrals on a bunch of different data... it uses headers from the boost library and also alglib. This all works fine on Windows machines running visual studios.
The issue I have is that when I include boost (which was installed via homebrew to usr/local/) into the search paths in the project build settings I get all sorts of semantic and linker issues.
I have searched this for a while and tried to implement a few potential fixes. I have tried:
Compiling with different C++ dialects and and standard libraries (libc++ and libstdc++).
Uninstalling/reinstalling boost.
Removing suggested header files and libraries from 'usr/local' suggested by brew doctor.
and implementing all sorts of other random permutations of settings that I felt could be issued.
The number of errors and warnings may change using different build settings however semantic issues persist and I am running out of ideas for how to proceed. It is really important I get this working and any insight would be appreciated.
From my reading about and attempting to troubleshoot I get the idea that it is some kind of linking issue between the boost library and the standard c++ libraries, but I have little experience with semantic issues as in the past I have been lucky enough that things just worked! Perhaps my MacBook may just have too much going on and needs some housecleaning to stop confusing the compiler, but regardless if anyone can help me fix this issue I would be eternally grateful!
I understand I haven't provided much detail here but if any information would be useful I'm happy to send screenshots.
link to errors image
In C++03 ifstream did not have a constructor that accepts std::string.
Such a constructor was added in C++11. The same holds for std::stod: it exists since C++11.
So you have to compile with -std=c++11 option.

Osmium in eclipse cdt

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?

How to compile c++11 code with android ndk and eclipse?

I'm using android NDK r8d, and eclipse Juno. I'm trying to compile C++ code which uses C++11 stuff like mutex, lock_guard, shared_ptr, etc. in a native android project in eclipse.
I get errors like:
"error: 'shared_ptr' is not a member of 'std'"
"fatal error: mutex: No such file or directory"
I came across a similar question here. It seems to work for them, but the explanation there is not complete so I can't get it to work for me.
I added "NDK_TOOLCHAIN_VERSION=4.7" to the Application.mk and "LOCAL_CFLAGS += -std=c++11" to Android.mk file. Still, it doesn't compile.
In the link above it says:
"Be sure that the standard library include path (like
/android-ndk-r8d/sources/cxx-stl/gnu-libstdc++/4.7/include) is in the
target settings."
How and where do I insert it?
I also get errors in eclipse IDE (on the source, before compiling). I know I should define "__GXX_EXPERIMENTAL_CXX0X__" to resolve them but I just don't know where to put it.
So, if someone could post an answer with a full explanation of how to compile and make eclipse work with C++11 it would be great.
Regarding your first question:
Go to Project > Properties > C/C++ General / Paths and Symbols
In the "Includes" tab, add the proper directory, e.g.
/android-ndk-r8d/sources/cxx-stl/gnu-libstdc++/4.7/include
Regarding your second question, I'm also looking for an answer. It is absolutely not clear how to define the GXX_EXPERIMENTAL_CXX0X macro in Eclipse.
Some say that it should be "added as a predefined macro to the indexer", but it looks like we both could not find a way to implement that...
I have read elsewhere that it should be added to "C/C++ General / Paths and Symbols / Symbols / GNU C++" but I can't find the "Symbols / GNU C++" part in my version of Indigo.
I find export an environment variable NDK_TOOLCHAIN_VERSION=4.8 before i start eclipse can solve this problem.
Eclipse use ndk's default toolchain version 4.6, if NDK_TOOLCHAIN_VERSION is not define, and gcc witch this version does not support all c++11's future like multithread and so on.

What C++ implementation/library is my IDE using? (NetBeans, MacOSX)

Can anyone tell me how an IDE like NetBeans or any for that matter gather all the standard C++ libraries? For example, I created a new Netbeans C++ application, and included iostream and it worked no problem. However, if I do a search for filename "iostream" on my MacOSX Snow Leapord, it finds it in the path
/Developer/SDKs/MacOSX10.6.sdk/System/Library/Frameworks/Kernel.framework/Versions/A/Headers/IOKit/stream
Does that mean that my IDE is using my operating system's C++ library? It's strange because all of these files are "copyright apple" - so I'm assuming that this is a C++ implementation modified by Apple?
I was under the impression that there was 1 standard C++ libary and all compilers used that. Is Netbeans somehow just gathering the same library that Xcode is bundled with?
Essentially, I'd like to view the source of some C++ headers to gather more information about their inner-workings, but I'm worried that I am using some super-heavyweight, Apple-modified core lib that may not even be legal to use because it's under some Apple liscense.
Thanks everyone
NetBeans is just an IDE, it doesn't come with a compiler or any C++ libraries. Since it looks like you already had Xcode installed, NetBeans automatically uses compilers and libraries associated with Xcode. I have no idea what the apple licenses are, but since you bought and own your Mac, I don't think there is a problem using those headers.
Also, to view headers, just right click the code and Go To -> C++ Declaration or Header Files.
There is a place you installed g++, and your include files all come from there.
You can add additional header files by using the gcc -I switch, and that is implemented in Netbeans in the build tool chain option
further information here
I don't have a mac in hand right now, but I guess the include files will be in somewhere like:
/usr/share/g++
EDIT:
You can find the code assistance pop-up include files at:
Tools -> Options -> C/C++ -> Code Assistance

Eclipse 3.7 cannot resolve Types in C++ Editor

I recently changed from Eclipse 3.6 to Eclipse 3.7 , which I am using for C++ development in Ubuntu 11.04 .
With Version 3.6 I had no big troubles, except that I always had some issues with the indexer.
Now with Version 3.7 it begins marking unresolved Types as Errors. Since the indexer seems to dislike me even more, my Eclipse apparently doesn't know types like uint16_t or size_t.
In contrary to the displayed errors in the code editor, my compiler has no problems with compiling the code and resolving all symbols and types, so this seems to be a problem of the IDE itself.
Are there any ways to avoid this behavior, because all the red underlines make my code more and more unreadable...?
Update:
Okay with some research and the answer from Dennis I found out that I need to add some paths to
Project Properties/ C/C++ General/ Paths and Symbols
Since I am building for a PowerPC instead of a I32 target, I can not just add /usr/include .
Instead I needed to add
/usr/powerpc-linux-gnu/libc/usr/include
for all the standard headers (like stdint.h).
Also I needed:
/usr/lib/gcc/powerpc-linux-gnu/4.5.1/include
for the stdarg.h.
Now almost all the errors are gone. The only function which still troubles me is printf from the header stdio.h. I looked it up and the header file itself lies within the included paths. Still I get an Error which says Function printf could not be resolved. I want to note again, that these are just errors displayed by Eclipse - The compiling itself works fine.
So this actually throws up 3 questions:
In the project properties the Paths and Symbols section coheres with the include Paths out of the C++ Build/Settings/C++ Includes section. This means adding/deleting a path in one of those sections directly affects the entry of the others. Since the C++ Includes directly coheres with the Compiler I wonder why the compiler can compile correcty ( and finds the headers ) even if they arent passed to him as a path? Is there some kind of standard path GCC uses, which I don't know about?
Why doesn't he find printf in eclipse? The headerfile stdio.h is included and it also contains the declaration of printf - so why does the Eclipse Code Editor tell me that it can't resolve it?
Why are the header files divided so much? I am aware that I need other header files if I am building for another traget (e.g. PowerPC) - But why does the GNU GCC separate those headers in different dirs?
The red underlines for common types are usually caused by not having your standard library in your include path. Look at your includes for your project... they are in the project properties. Ensure that your C++ includes have an entry that matches the C++ standard libs folders for the compiler you are using.
After hitting this problem and a search revealing two stack overflow questions hitting the same problem, I figured I would submit how I fixed it after it annoyed me enough to actually investigate.
I'm running Fedora and annoyingly, it has a stddef.h file in /usr/include/linux.... which is actually empty. So even though I had the compiler's stddef.h in the include path, the indexer was actually parsing this other empty file. So what needed done was:
Prefix your paths and symbols list with the compiler specific include path (in my case it was /usr/lib/gcc/x86_64-redhat-linux/4.7.2/include/) to avoid the other empty stddef.h from being parsed.
I'm using Eclipse (Mars.1 Release 4.5.1, Build id: 20150924-1200) with an ARM compiler (arm-none-eabi, 4.4.1).
I had exactly the same problem as you.
My former path was:
D:\test\CodeSourcery\Sourcery G++ Lite\lib\gcc\arm-none-eabi\4.4.1\include
Then i discovered another include directory (postfix: 'fixed') at the compiler directories:
D:\test\CodeSourcery\Sourcery G++ Lite\lib\gcc\arm-none-eabi\4.4.1\include-fixed
This fixed all my errors concerining type-misdetection (e. g. uint16_t).