Eclipse indexer can't resolve shared_ptr - c++

After researching this on the internet, I've been unable to get the Eclipse indexer to resolve "shared_ptr" from the C++0x additions that come with GCC 4.4.4. I made sure to create my project with the proper includes for Eclipse, so it's definitely looking in the the 4.4.4 include folders.
The program compiles and runs just fine. To access shared_ptr I'm using "#include <memory>".
Any idea what's breaking the indexer?

You need to set the pre-processor symbol '__GXX_EXPERIMENTAL_CXX0X__' to the eclipse project. g++ automatically adds that when you use '-std=c++0x', but eclipse is not aware of that, so it treats those sections of the relevant headers as disabled.

I experienced this problem under Windows with Eclipse 4.5.1 (Mars.1) and Cygwin 2.3.0 (GCC 4.9.3).
The indexer can't find shared_ptr because of lines like this in the <memory> header. The __cplusplus macro is evaluating to something other than C++ 11 (aka 201103) so the older auto_ptr.h is being included instead of shared_ptr.h. Why? The below screen shot of the project properties shows that C++ 98 (199711) is being detected under CDT GCC Build-in Compiler Settings.
#if __cplusplus >= 201103L
# include <bits/shared_ptr.h>
#else
# include <backward/auto_ptr.h>
#endif
There are two possible solutions to tell Eclipse to use C++ :
On the same Preprocessor Include Paths screen, scroll to the top of the Setting Entries area. Expand CDT User Setting Entries. Add a new Preprocessor Macro for __cplusplus=201103L. Do this for both the Release and Debug Configurations. Then rebuild the index.
If you want to default the CDT GCC Build-in Compiler Settings to use 201103 for all projects, then edit the language.settings.xml file (under Windows this is c:\Users\deanhill\workspace\.metadata\.plugins\org.eclipse.cdt.core\language.settings.xml). Set __cplusplus=201103L. Restart Eclipse and rebuild the index.

Although I am late to the game, this is what worked for me:
Right-Click on Project->Properties->C/C++ General->Preprocessor Include Paths, Macros, etc. --> Click "Providers" tab --> CDT GCC Built-in Compiler Settings
Uncheck "Use global provider shared between projects"
Add -std=c++0x
It will then look something like this:
${COMMAND} ${FLAGS} -E -P -v -dD -std=c++0x "${INPUTS}"
Rebuild index.
Using Debian Jessie + Eclipse Kepler Build id: 20140224-0627

I experienced the same problem. I have added the GXX_EXPERIMENTAL_CXX0X as well as -std=c++11 to compiler options in workspace. However it did not solve my problem.
I was missing one more step:
Right-Click on Project->Properties->C/C++ Build->Settings->Cross G++ Compiler->Miscellaneous->Other flags
I changed
-c -fmessage-length=0
to
-c -fmessage-length=0 -std=c++11
Now Eclipse sees std::shared_ptr and indexes it correctly.

For me it worked by setting other dialect flags = -std=c++11 under:
Preferences -> C++ Build -> Settings -> GCC C++ Compiler -> Dialect,
as well as adding -std=c++11 under:
Preferences -> C++ General -> Preprocessor Include Path -> Providers -> CDT GCC Build-in Compiler Settings -> command to get compiler specs.
Do not forget to clean and rebuild your Project/Index.

Related

exe file won't run on other devices [duplicate]

I have been working on a project (a game to be specific) and I feel that I should start over with different libraries. So when doing this I reinstalled Code::Blocks and setup my new libraries and includes.
But as of now Im having a problem starting u[ my new project to test if all of the includes work. This problem is: libstdc++-6.dll was not found. At first i wondered if I could just find this file online, but its nowhere to be found(or at least the many places I have searched...) Soon after, I tried loading up my old project, and the same problem happened again(wierd... ._.) I was thinking its maybe my compiler, so I used my older compiler and it did the same thing! At this moment I held the problem off for tomorrow(which is today)
So my question is: If anyone else had this problem, how would you solve it?
Im using Code::Blocks with MinGW as the compiler on Windows Vista 32 bit.
*****EDIT*****
Here are the Build options in my project. Note that these are the settings in the Project, not the global compiler:
In (project name)->Compiler settings->Otehr options:
(I use // to seperate the commands)
-mthreads//
-fmessage-length=0//
-fexceptions//
-fident//
In (project name)->Compiler settings->#define:
WIN32//
_WINDOWS//
In (project name)->Linker settings->Other linker options:
-static-libstdc++//
-static-libgcc//
-Wl,--enable-auto-image-base//
-Wl,--add-stdcall-alias//
-Wl,--enable-auto-import//
In linker->link libraries i have various links to files with a .a extension, these files include Bullet PHysics, Ogre3D, and SFML
In the search directories i have links to the MinGW/bin, and the MinGW/lib directories, along with other links to different libraries.
My Compiler is MinGW, a GNU GCC compiler for windows 32 bit. and the IDE is Codeblocks. Also note that in Debug and Release settings on the project, there is nothing.
Most of these setings are also pieces that i got from the Ogre3D Application setup tutorial if that is of any help.
If you are using MingW to compile C++ code on Windows, you may like to add the options -static-libgcc and -static-libstdc++ to link the C and C++ standard libraries statically and thus remove the need to carry around any separate copies of those. Version management of libraries is a pain in Windows, so I've found this approach the quickest and cleanest solution to creating Windows binaries.
As far as I know, this is the C++ Runtime Library. So it depends on the compiler you use to create your program (A new version will include some C++0x stuff, an older version will probably not for instance. It depends of the compiler and of its version).
If you use MinGW then you should use the libstdc++-6.dll found into the folder of this compiler. MinGW/bin folder should be the place to search for it on your computer.
If you copy this file in the same directory as your executable, it should be OK.
Simply removing libstdc++-6.dll.a \ libstdc++.dll.a from the mingw directory fixes this.
I tried using the flag -static-libstdc++ but this did not work for me.
I found the solution in: http://ghc.haskell.org/trac/ghc/ticket/4468#
This error also occurred when I compiled with MinGW using gcc with the following options:
-lstdc++ -lm, rather than g++
I did not notice these options, and added: -static-libgcc -static-libstdc++
I still got the error, and finally realized I was using gcc, and changed the compiler to g++ and removed -stdc++ and -lm, and everything linked fine.
(I was using LINK.c rather than LINK.cpp... use make -pn | less to see what everything does!)
I don't know why the previous author was using gcc with -stdc++. I don't see any reason not to use g++ which will link with stdc++ automatically... and as far as I know, provide other benefits (it is the c++ compiler after all).
useful to windows users who use eclipse for c/c++ but run *.exe file and get an error: "missing libstdc++6.dll"
4 ways to solve it
Eclipse ->"Project" -> "Properties" -> "C/C++ Build" -> "Settings" -> "Tool Settings" -> "MinGW C++ Linker" -> "Misscellaneous" -> "Linker flags" (add '-static' to it)
Add '{{the path where your MinGW was installed}}/bin' to current user environment variable - "Path" in Windows, then reboot eclipse, and finally recompile.
Add '{{the path where your MinGW was installed}}/bin' to Windows environment variable - "Path", then reboot eclipse, and finally recompile.
Copy the file "libstdc++-6.dll" to the path where the *.exe file is running, then rerun. (this is not a good way)
Note: the file "libstdc++-6.dll" is in the folder '{{the path where your MinGW was installed}}/bin'
I use Eclipse under Fedora 20 with MinGW for cross compile.
Use these settings and the program won't ask for libstdc++-6.dll any more.
Project type - Cross GCC
Cross Settings
Prefix: x86_64-w64-mingw32-
Path: /usr/bin
Cross GCC Compiler
Command: gcc
All Options:
-I/usr/x86_64-w64-mingw32/sys-root/mingw/include -O3
-Wall -c -fmessage-length=0
Includes: /usr/x86_64-w64-mingw32/sys-root/mingw/include
Cross G++ Compiler
Command: g++
All Options: -I/usr/x86_64-w64-mingw32/sys-root/mingw/include -O3
-Wall -c -fmessage-length=0
Includes: /usr/x86_64-w64-mingw32/sys-root/mingw/include
Cross G++ Linker
Command: g++ -static-libstdc++ -static-libgcc
All Options: -L/usr/x86_64-w64-mingw32/sys-root/mingw/lib -L/usr/x86_64-w64-mingw32/sys-root/mingw/bin
Library search path (-L):
/usr/x86_64-w64-mingw32/sys-root/mingw/lib
/usr/x86_64-w64-mingw32/sys-root/mingw/bin
I just had this issue.. I just added the MinGW\bin directory to the path environment variable, and it solved the issue.
I placed the libstdc++-6.dll file in the same folder where exe file is generated.
You only need to add your "mingw-install-directory"/bin/ to your Path in your System environment variables ... that's it !!
I had same problem. i fixed it. i was using Codeblocks and i save my .cpp file on desktop instead of saving it in Codeblocks file where MinGW is located. So i copied all dll files from MinGW>>bin folder to where my .cpp file was saved.
You can also copy the dll files in the directory of your exe file
I had this problem too. I was compiling in command prompt and used the flag -static.
My command before:
"g++ test.cpp -o test.exe"
and afterwards:
"g++ test.cpp -o test.exe -static"
I had the same problem and I solved it by running the compiled exe as an administrator.

Unresolved Inclusions using C++ [duplicate]

I download eclipse for c++ (cdt-master-8.0.2.zip).
When I write:
#include <iostream>
It marks:
Unresolved inclusion: <iostream>
How can I fix it?
Click Project → Properties.
Expand C/C++ General.
Click Preprocessor Include Paths, Macros, etc.
Click the Providers tab.
Check CDT GCC Built-in Compiler Settings.
Check Use global provider shared between projects.
Click Apply and Close.
I use Eclipse for cross compiling and I have to add the explicit directories for some of the standard C++ libraries. Right click your project and select Properties. You'll get the dialog shown in the image. Follow the image and use the + icon to explicitly add the paths to your C++ libraries.
Make sure that your file has .cpp extension and not .c, I just had this problem
I tried all previously mentioned answers, but in my case I had to manually specify the include path of the iostream file. As I use MinGW the path was:
C:\MinGW\lib\gcc\mingw32\4.8.1\include\c++
You can add the path in Eclipse under:
Project > C/C++ General > Paths and Symbols > Includes > Add. I hope that helps
Install gcc.
If you're on linux, use the package manager.
If you're on Windows, use MinGW.
In my case, it was not the CDT GCC Built-in Compiler Settings. Only after I included CDT GCC Built-in Compiler Settings Cygwin did the parser recognized my #include <iostream>.
It sounds like you haven't used this IDE before. Read Eclipse's "Before You Begin" page and follow the instructions to the T. This will make sure that Eclipse, which is only an IDE, is actually linked to a compiler.
http://help.eclipse.org/indigo/index.jsp?topic=/org.eclipse.cdt.doc.user/concepts/cdt_c_before_you_begin.htm
I'm using Eclipse with Cygwin and this worked for me:
Go to Project > Properties > C/C++ General > Preprocessor Includes... > Providers
and select "CDT GCC Built-in Compiler Settings Cygwin [Shared]".
For those using a fresh install of Ubuntu, or another Linux distro,
make sure your have at least the package "build-essential" before you try to compile Eclipse CDT projects.
At Terminal, type:
sudo apt-get install build-essential
It should be enough to compile and run your apps.
Of course, you can also perform full g++ install, using:
sudo apt-get install g++
I am running eclipse with cygwin in Windows.
Project > Properties > C/C++ General > Preprocessor Includes... > Providers
and selecting "CDT GCC Built-in Compiler settings Cygwin" in providers list solved problem for me.
Also set ${COMMAND} to g++ on Linux
Under:
Project
Properties
C/C++ General
Preprocessor Include Paths, Macros, etc.
Providers
CDT GCC Built-in Compiler Settings
Command to get compiler specs
Replace:
${COMMAND} ${FLAGS} -E -P -v -dD "${INPUTS}"
with:
g++ -std=c++11 -E -P -v -dD "${INPUTS}"
If you don't do this, the Eclipse stdout shows:
Unable to find full path for "-E"
and logs under ${HOME}/eclipse-workspace/.metadata/.log show:
!ENTRY org.eclipse.cdt.core 4 0 2020-04-23 20:17:07.288
!MESSAGE Error: Cannot run program "-E": Unknown reason
because ${COMMAND} ${FLAGS} are empty, and so Eclipse tries to execute the -E that comes next.
I wonder if we can properly define the COMMAND and FLAGS variables on the settings, but I tried to add them as build variables and it didn't work.
C version of the question: "Unresolved inclusion" error with Eclipse CDT for C standard library headers
Tested on Eclipse 2020-03 (4.15.0), Ubuntu 19.10, and this minimal Makefile project with existing sources.
On Windows, with Eclipse CDT Oxygen, none of the solutions described here worked for me. I described what works for me in this other question: Eclipse CDT: Unresolved inclusion of stl header.
I'd had this issue with Eclipse 2019-12 where the includes were previously being resolved, but then weren't. This was with a Meson build C/C++ project. I'm not sure exactly what happened, but closing the project and reopening it resolved the issue for me.

C++ windows executable compiled with Linux needs additional DLL [duplicate]

I have been working on a project (a game to be specific) and I feel that I should start over with different libraries. So when doing this I reinstalled Code::Blocks and setup my new libraries and includes.
But as of now Im having a problem starting u[ my new project to test if all of the includes work. This problem is: libstdc++-6.dll was not found. At first i wondered if I could just find this file online, but its nowhere to be found(or at least the many places I have searched...) Soon after, I tried loading up my old project, and the same problem happened again(wierd... ._.) I was thinking its maybe my compiler, so I used my older compiler and it did the same thing! At this moment I held the problem off for tomorrow(which is today)
So my question is: If anyone else had this problem, how would you solve it?
Im using Code::Blocks with MinGW as the compiler on Windows Vista 32 bit.
*****EDIT*****
Here are the Build options in my project. Note that these are the settings in the Project, not the global compiler:
In (project name)->Compiler settings->Otehr options:
(I use // to seperate the commands)
-mthreads//
-fmessage-length=0//
-fexceptions//
-fident//
In (project name)->Compiler settings->#define:
WIN32//
_WINDOWS//
In (project name)->Linker settings->Other linker options:
-static-libstdc++//
-static-libgcc//
-Wl,--enable-auto-image-base//
-Wl,--add-stdcall-alias//
-Wl,--enable-auto-import//
In linker->link libraries i have various links to files with a .a extension, these files include Bullet PHysics, Ogre3D, and SFML
In the search directories i have links to the MinGW/bin, and the MinGW/lib directories, along with other links to different libraries.
My Compiler is MinGW, a GNU GCC compiler for windows 32 bit. and the IDE is Codeblocks. Also note that in Debug and Release settings on the project, there is nothing.
Most of these setings are also pieces that i got from the Ogre3D Application setup tutorial if that is of any help.
If you are using MingW to compile C++ code on Windows, you may like to add the options -static-libgcc and -static-libstdc++ to link the C and C++ standard libraries statically and thus remove the need to carry around any separate copies of those. Version management of libraries is a pain in Windows, so I've found this approach the quickest and cleanest solution to creating Windows binaries.
As far as I know, this is the C++ Runtime Library. So it depends on the compiler you use to create your program (A new version will include some C++0x stuff, an older version will probably not for instance. It depends of the compiler and of its version).
If you use MinGW then you should use the libstdc++-6.dll found into the folder of this compiler. MinGW/bin folder should be the place to search for it on your computer.
If you copy this file in the same directory as your executable, it should be OK.
Simply removing libstdc++-6.dll.a \ libstdc++.dll.a from the mingw directory fixes this.
I tried using the flag -static-libstdc++ but this did not work for me.
I found the solution in: http://ghc.haskell.org/trac/ghc/ticket/4468#
This error also occurred when I compiled with MinGW using gcc with the following options:
-lstdc++ -lm, rather than g++
I did not notice these options, and added: -static-libgcc -static-libstdc++
I still got the error, and finally realized I was using gcc, and changed the compiler to g++ and removed -stdc++ and -lm, and everything linked fine.
(I was using LINK.c rather than LINK.cpp... use make -pn | less to see what everything does!)
I don't know why the previous author was using gcc with -stdc++. I don't see any reason not to use g++ which will link with stdc++ automatically... and as far as I know, provide other benefits (it is the c++ compiler after all).
useful to windows users who use eclipse for c/c++ but run *.exe file and get an error: "missing libstdc++6.dll"
4 ways to solve it
Eclipse ->"Project" -> "Properties" -> "C/C++ Build" -> "Settings" -> "Tool Settings" -> "MinGW C++ Linker" -> "Misscellaneous" -> "Linker flags" (add '-static' to it)
Add '{{the path where your MinGW was installed}}/bin' to current user environment variable - "Path" in Windows, then reboot eclipse, and finally recompile.
Add '{{the path where your MinGW was installed}}/bin' to Windows environment variable - "Path", then reboot eclipse, and finally recompile.
Copy the file "libstdc++-6.dll" to the path where the *.exe file is running, then rerun. (this is not a good way)
Note: the file "libstdc++-6.dll" is in the folder '{{the path where your MinGW was installed}}/bin'
I use Eclipse under Fedora 20 with MinGW for cross compile.
Use these settings and the program won't ask for libstdc++-6.dll any more.
Project type - Cross GCC
Cross Settings
Prefix: x86_64-w64-mingw32-
Path: /usr/bin
Cross GCC Compiler
Command: gcc
All Options:
-I/usr/x86_64-w64-mingw32/sys-root/mingw/include -O3
-Wall -c -fmessage-length=0
Includes: /usr/x86_64-w64-mingw32/sys-root/mingw/include
Cross G++ Compiler
Command: g++
All Options: -I/usr/x86_64-w64-mingw32/sys-root/mingw/include -O3
-Wall -c -fmessage-length=0
Includes: /usr/x86_64-w64-mingw32/sys-root/mingw/include
Cross G++ Linker
Command: g++ -static-libstdc++ -static-libgcc
All Options: -L/usr/x86_64-w64-mingw32/sys-root/mingw/lib -L/usr/x86_64-w64-mingw32/sys-root/mingw/bin
Library search path (-L):
/usr/x86_64-w64-mingw32/sys-root/mingw/lib
/usr/x86_64-w64-mingw32/sys-root/mingw/bin
I just had this issue.. I just added the MinGW\bin directory to the path environment variable, and it solved the issue.
I placed the libstdc++-6.dll file in the same folder where exe file is generated.
You only need to add your "mingw-install-directory"/bin/ to your Path in your System environment variables ... that's it !!
I had same problem. i fixed it. i was using Codeblocks and i save my .cpp file on desktop instead of saving it in Codeblocks file where MinGW is located. So i copied all dll files from MinGW>>bin folder to where my .cpp file was saved.
You can also copy the dll files in the directory of your exe file
I had this problem too. I was compiling in command prompt and used the flag -static.
My command before:
"g++ test.cpp -o test.exe"
and afterwards:
"g++ test.cpp -o test.exe -static"
I had the same problem and I solved it by running the compiled exe as an administrator.

How to solve "Unresolved inclusion: <iostream>" in a C++ file in Eclipse CDT?

I download eclipse for c++ (cdt-master-8.0.2.zip).
When I write:
#include <iostream>
It marks:
Unresolved inclusion: <iostream>
How can I fix it?
Click Project → Properties.
Expand C/C++ General.
Click Preprocessor Include Paths, Macros, etc.
Click the Providers tab.
Check CDT GCC Built-in Compiler Settings.
Check Use global provider shared between projects.
Click Apply and Close.
I use Eclipse for cross compiling and I have to add the explicit directories for some of the standard C++ libraries. Right click your project and select Properties. You'll get the dialog shown in the image. Follow the image and use the + icon to explicitly add the paths to your C++ libraries.
Make sure that your file has .cpp extension and not .c, I just had this problem
I tried all previously mentioned answers, but in my case I had to manually specify the include path of the iostream file. As I use MinGW the path was:
C:\MinGW\lib\gcc\mingw32\4.8.1\include\c++
You can add the path in Eclipse under:
Project > C/C++ General > Paths and Symbols > Includes > Add. I hope that helps
Install gcc.
If you're on linux, use the package manager.
If you're on Windows, use MinGW.
In my case, it was not the CDT GCC Built-in Compiler Settings. Only after I included CDT GCC Built-in Compiler Settings Cygwin did the parser recognized my #include <iostream>.
It sounds like you haven't used this IDE before. Read Eclipse's "Before You Begin" page and follow the instructions to the T. This will make sure that Eclipse, which is only an IDE, is actually linked to a compiler.
http://help.eclipse.org/indigo/index.jsp?topic=/org.eclipse.cdt.doc.user/concepts/cdt_c_before_you_begin.htm
I'm using Eclipse with Cygwin and this worked for me:
Go to Project > Properties > C/C++ General > Preprocessor Includes... > Providers
and select "CDT GCC Built-in Compiler Settings Cygwin [Shared]".
For those using a fresh install of Ubuntu, or another Linux distro,
make sure your have at least the package "build-essential" before you try to compile Eclipse CDT projects.
At Terminal, type:
sudo apt-get install build-essential
It should be enough to compile and run your apps.
Of course, you can also perform full g++ install, using:
sudo apt-get install g++
I am running eclipse with cygwin in Windows.
Project > Properties > C/C++ General > Preprocessor Includes... > Providers
and selecting "CDT GCC Built-in Compiler settings Cygwin" in providers list solved problem for me.
Also set ${COMMAND} to g++ on Linux
Under:
Project
Properties
C/C++ General
Preprocessor Include Paths, Macros, etc.
Providers
CDT GCC Built-in Compiler Settings
Command to get compiler specs
Replace:
${COMMAND} ${FLAGS} -E -P -v -dD "${INPUTS}"
with:
g++ -std=c++11 -E -P -v -dD "${INPUTS}"
If you don't do this, the Eclipse stdout shows:
Unable to find full path for "-E"
and logs under ${HOME}/eclipse-workspace/.metadata/.log show:
!ENTRY org.eclipse.cdt.core 4 0 2020-04-23 20:17:07.288
!MESSAGE Error: Cannot run program "-E": Unknown reason
because ${COMMAND} ${FLAGS} are empty, and so Eclipse tries to execute the -E that comes next.
I wonder if we can properly define the COMMAND and FLAGS variables on the settings, but I tried to add them as build variables and it didn't work.
C version of the question: "Unresolved inclusion" error with Eclipse CDT for C standard library headers
Tested on Eclipse 2020-03 (4.15.0), Ubuntu 19.10, and this minimal Makefile project with existing sources.
On Windows, with Eclipse CDT Oxygen, none of the solutions described here worked for me. I described what works for me in this other question: Eclipse CDT: Unresolved inclusion of stl header.
I'd had this issue with Eclipse 2019-12 where the includes were previously being resolved, but then weren't. This was with a Meson build C/C++ project. I'm not sure exactly what happened, but closing the project and reopening it resolved the issue for me.

Eclipse CDT Builtin Include Directories

Under
Eclipse CDT >
Project Settings >
C/C++ General >
Paths and Symbols >
Includes >
GNU C++
There is a list of include paths.
Some are in bold and are project specific.
Others are builtin:
For example:
/usr/include/C++/4.6/
/usr/include/x86_64-linux-gnu
etc
If I delete:
work/.metadata/.plugins/org.eclipse.cdt.make.core/*.sc
The paths are automatically rescanned when Eclipse launches.
I have gcc 4.6 and gcc 4.7 installed side-by-side.
When Eclipse rescans it only finds the 4.6 headers and not the 4.7 ones.
My question is this: By what mechanism does Eclipse determine the list of builtin include paths? (and hence why is it only finding the 4.6 headers and not the 4.7 headers?)
This is controlled by the settings on Project->Properties->C/C++ Build->Discovery Options. By default, Eclipse will call g++ to discover the include directories. The first instance of g++ on the path will be the one that gets invoked. You can always set the full path to the compiler you want it to use for your project.