eclipse cdt - change type of project - c++

I have a bunch of Eclipse projects imported into my workspace.
I know how to add a directory for Eclipse to search for headers to resolve symbols.
However, some of my projects do not allow me to add these directories and I realized that it's because those projects are not the correct type.
Right click > Properties on the 'correct' type of project shows an item in the list called "C/C++ Build
If it has this entry, then in C/C++ General it has an entry called Paths and Symbols wherein I can add necessary include directories so that the indexing works.
QUESTION
How do I change the properties of this project so I can use indexing and add directories for indexing?
I've found one thing that obviously needs to be changed: in the 'correct' project, Right Click > Properties > Builders has two entries: CDT Builder and Scanner Configuration Builder while the 'incorrect' project is missing these two.
How do I add them?
Import yields a blank page and New is just as useless.

You probably want File -> New -> Convert to a C/C++ Project (Adds C/C++ Nature).

Related

Header file not found in Eclipse CDT

I'm trying to build a project that uses an external library (Casablanca) using Eclipse CDT 8.8.1. on Mac OS. As expected, the first build run returned "cpprest/http_client.h file not found" errors.
I then proceeded to add an include path (/Users/me/projects/casablanca/Release/include) by right-clicking on the project, selecting Properties->C/C++ Include Paths and Symbols, Add External Include Path, and moving it up in priority as the first listed folder.
However this did not solve the problem and Eclipse still can't seem to find the headers. The #include directive is as below:
#include <cpprest/http_client.h>
and the added /include directory does have a /cpprest sub-directory, with http_client.h in it.
Any help would be appreciated.
Adding an include path to Project Properties | C/C++ General | Paths and Symbols only adds the include path to the set of includes searched by CDT's indexer when indexing the project.
The actual build system needs to be told the include path by another means. If you're using a Managed Build project (as opposed to a Makefile project) - which it sounds like you are - you would add the include path in Project Properties | C/C++ Build | Settings. Note that the indexer automatically picks up build settings, so once you do this, there shouldn't be a need to also add it to Paths and Symbols.
This answer applies if:
You do not have a C++ Managed Build Project (for example, you have a C++ Makefile project as I do).
and
Various things in the code editor are underlined in red because a header file is not detected.
In my case, the indexer found the headers (and all the red underlines went away) when I added the include directories to Project Properties > C/C++ General > Preprocessor Includes > Select GNU C++ > Select CDT User Settings Entries > Press Add. Make sure the combo boxes (aka drop down menus) are set to "Include Directory" and "File System Path". Type in or browse for the include directory. Then press OK > OK.
Note that prior to this I tried adding the include directory to Project Properties > C/C++ General > Paths and Symbols > GNU C++ > Add, but this did not solve the problem alone.
Based on some quick testing it seems that the Paths and Symbols > GNU C++ > etc includes are unnecessary assuming you are using an external build system.
I am using Eclipse 3.8.1 on Ubuntu 16.04 with Eclipse CDT 8.6.0.

Eclipse CDT: nothing could be resolved?

I have a very strange error/bug here:
From one hour to the next, Eclipse isn't able to resolve any of the symbol. E.g.:
std, list, [own objects], or functions like: size(), append(), cout and so on ...
I already rebuild and /refreshed the indexer over the whole project and tried to clean it too. But without any effort. The only thing new I did was yesterday: I added Doxygen support to my project.
I have no idea where this comes from. I think sending all the source code is way too big, it has to be a general Eclips-Error, since I was working like this for weeks.
Eclipse version: Kepler Service Release 2
Has anyone an idea?
UPDATE
Thank you for your Support and pardon me I have switched my whole system, thus I can't reproduce your suggestions anymore.
there are two ways:
use system's default lib: when you create the project using "New Project", you can select the "Toolchain for Indexer Setting". For example, I am using Eclipse in Linux so I just choose "Linux GCC". And after the project is created, all the headers will be automatically included for you.
use you own version of the lib: you need to tell Eclipse the paths to search for the include. Right click the project name, select "C/C++ General" -> "Paths and Symbols" -> "GNU C++". And you can add your paths there.
Most likely you have some system-specific include directories missing in your settings which makes it impossible for indexer to correctly parse iostream, thus the errors. Selecting Index -> Search For Unresolved Includes in the context menu of the project will give you the list of unresolved includes which you can search in /usr/include and add containing directories to C++ Include Paths and Symbols in Project Properties.
On my system I had to add /usr/include/c++/4.6/x86_64-linux-gnu for bits/c++config.h to be resolved and a few more directories.
Don't forget to rebuild the index (Index -> Rebuild) after adding include directories.

Reset property page settings Visual Studio C 2010 Express

I made some changes to the Property Pages/Configuration Properties a long time ago and I'd like to reset them. I changed stuff like the output directory, code generation settings, etc.
I've tried resetting all environment settings from the Import and Export Settings Wizard. I've also tried the devenv /resetsettings command. Both of which did not work. Reinstalling doesn't work either. May I get some advice on how to restore everything back to the default.
Thank you.
If I understand you correctly, you are trying to revert to old settings for the Project -> Properties.
This information is stored in the project itself, not in Visual Studio. Look for a file with the extension vcxproj in the solution folder.
You can edit it with Notepad (notepad++), or - you can edit it inside Visual Studio, by
right-click the project, unload it, then edit project file, then reload project
Be careful how you edit these settings.
For best results, create a new solution, with a new project, and compare the settings from the newly created project with the existing one.
edit: on my computer (I have VS Ultimate I think, but it shouldn't matter):
To edit, go to Project -> Properties -> VC++ Directories, and on each, at the end of the line, press the arrow down, and click Edit...
VC++ directories:
$(VCInstallDir)bin
$(WindowsSdkDir)bin\NETFX 4.0 Tools
$(WindowsSdkDir)bin
$(VSInstallDir)Common7\Tools\bin
$(VSInstallDir)Common7\tools
Include Directories:
$(VCInstallDir)include
$(VCInstallDir)atlmfc\include
$(WindowsSdkDir)include
$(FrameworkSDKDir)\include
from what I see in the directions you pointed out, all you have to do is remove from your list, the directories that you no longer want.
In c/c++ -> Code Generation ->
enable minimal rebuild: NO
enable c++ exceptions: YES (/EHSC)
Basic Runtime Checks - Both
/MTd
...
General -> Output directory:
not sure what is the default, I would put something like
$(SolutionDir)bin\$(Platform)\$(Configuration)\
Also, there seems to be a property sheet that may have been added to your project...
You can generally see the Property Manager from View -> Properties Window (F4).
here, you can expand the project configurations, and simply delete any property sheets you may not want (I expect a new project to have no property sheets).

Eclipse indexing not working

I am using CDT in Eclipse 3.5.2 Galileo in Ubuntu.
My eclipse's indexer doesn't work at times. By that I mean when I ctrl click a function it says Could not find symbol in index. Also, F3 button click results in the same error message. Actually most of the places it is not working and works in very few places.
I have seen some other versions of Eclipse where under File menu a menu item listed for Indexing. Like File->Indexer->Rebuild.... But in my File menu there is no such menu item for the Indexer.
Will the only way be to use some other release of Eclipse or am missing something? Any pointers regarding this would be helpful.
In my case nothing has worked and at last I did the following:
1) Close the project
2) Delete the project(do not check from disk option)
3) create new project with existing code(use the deleted project path)
4) Successfully indexed my c++ code
To add paths containing code to parse, follow these steps :
1. Right click on the project
2. Select Properties
3. Go to C/C++ General
4. Go to Path and Symbols
5. If the paths are missing, add paths.
To re-parse the code follow these steps :
1. Right click on the project
2. Select Index
3. Rebuild
If this doesn't work, then you are out of luck. c++ is very difficult language to parse.
If your indexer is stuck and it hangs for infinite time, you can delete the indexer related files of your project from .metadata. Make sure eclipse is not running in the meanwhile.
The .metadata directory is located as a hidden folder in the path of your workspace.
There you can navigate to:
<workspace_path>/.metadata/.plugins/org.eclipse.core.runtime/.settings/
Inside the .settings/ directory there are .prefs files which store the preferences of each project individually.
For example: org.eclipse.cdt.core.prj-test-project.prefs stores the preferences of the project test-project
Open this file with the text editor and remove all the lines starting with indexer. This will reset the indexer settings for this specific project to the default.
Alternatively, you can remove all the lines starting with indexer from org.eclipse.cdt.core.prefs; doing this will reset the indexer settings for the whole workspace.
I believe you can clear the index by running:
rm .metadata/.plugins/org.eclipse.jdt.core/*.index
And then restarting Eclipse. It will then rebuild its index.
This worked for me in a Java project, but I imagine its the same index for all (most?) project types.
Right click on the project.
Select New->Convert to a C++ Project.
Select your configuration. And then Next
Indexer will start indexing all the files.
For me this worked:
Right click and close the project
Open the project again
Right click and select Index->Rebuild
I hope it helps anybody.
You can try rebuilding the index.
Right-click on the project in Project View. Then Index -> Rebuild.
Here is the solution I used after Project->C++ Index->Rebuild failed. This trick avoid deleting your current project :
1) Copy the current project (Right click->Copy from Project Explorer)
2) Paste it (Right click->Paste from Project Explorer) and give the copy another name
3) The indexer should now start and index both projects
4) When indexation is complete, you can delete the copy
PS: Make sure your original project is an actual C++ Project or this will obviously not work.
Convert a project to C or C++ nature:
Right click on project: New >  Convert to C/C++ Project
In "Convert to C or C++": Choose C/C++ Project
In "Project options": Check "Specify Project Type"
...Project Type: Choose "Makefile project"
...Toolchains: Gross GCC
I was having the same problem and it turns out that the index folder was owned by root (I must have run Eclipse as a root once for some reason) I reclaimed the project folder using sudo chown -R username projectfolderpath and problem solved.
Execute eclipse.exe -clean -refresh where the eclipse is installed.
Create a new C/C++ Project in Eclipse with Given Source code folder path. (Not with New Project based on existing workspace)
Above steps worked for me.
For me it was issue that when creating a project indexer was chosen as none. Deleted the project and while creating the project again I chose the indexer options as per my need "LINUX_GCC", then it worked for me
Just came across the same problem in my C++ ARM Cross GCC project. I'm developing on Windows, using Makefile and an Ubuntu Docker image with GNU ARM Embedded Toolchain to build the project.
The solution to get rid of the unresolved symbols, in my case, could be divided into two parts:
The CDT Arm Cross GCC Built-in Compiler Settings didn't have the path to the compiler.
In the Project Properties -> C/C++ General -> Preprocessor Include Paths -> Providers(tab) the path to the compiler must be provided.
Using the GNU ARM Embedded Toolchain, the entry for the Command to get compiler specs: I currently use is:
C:\GNU_Arm_Embedded_Toolchain\9-2020-q2-update\bin\arm-none-eabi-g++.exe ${FLAGS} ${cross_toolchain_flags} -E -P -v -dD "${INPUTS}"
Note: Yes, I am having installed the same toolchain on my Windows machine as I'm using in the Docker image.
To verify, that the call is correct, you can tick the Allocate console in the Console View, which will provide hlepful output to the Console. Also, in the Entries tab, when you unroll the CDT Arm Cross GCC Built-in Compiler Settings you should see the includes and symbols included.
Missing symbol in the Project Properties -> C/C++ General -> Paths and Symbols menu.
As I have my defines in the Makefile, I forgot to add the define of my MCU also here.
Hope this helps to someone! :)
For the most part, the other answers tackle the situation wherein one "had" a working index earlier and things have gone astray for some reason.
On the other hand, I faced a problem wherein I needed to install everything from scratch (eclipse, workspace, c++ project etc.) and the indexing just wouldn't work. I finally found the solution here: https://www.eclipse.org/forums/index.php/t/1109004/
The key inputs from the above page are:
You need to setup include paths for the Indexer just as you would need
to for the compiler. The Indexer and compiler are completely independent.
The Indexer include paths are set by
Project -->Properties --> C/C++ General --> Preprocessor Include Paths, Macros etc. --> Entries tab --> CDT UserSettings Entries ...
and
You could try using
Project --> Properties --> C/C++ General --> Paths and Symbols
That's supposed to merge telling the compiler and Indexer
in one place.
However, this latter part of the suggestion did not work for me.

How do I include a statically linked library in my Eclipse C++ project?

I have an open-source library that's distributed in source form. After I run the Makefile, I end up with a .h file and a .a file that I then want to include in a project that I'm working on. I'm familiar with how I can add these by editing a Makefile manually or by invoking the compiler from the command line, but I'm not sure how I can add these to my Eclipse C++ project, created using the CDT.
I'm currently using Eclipse Indigo. I found some instructions for older versions of Eclipse, but the menus aren't what are described. I poked around a bit, and didn't see anything familiar.
right click on the project name in the project explorer with the project being opened, select project properties. Then select C/C++ General -> Paths and Symbols -> includes -> GNU C++ and add the path to your header file. You should do the same for you library under : C/C++ General -> Paths and Symbols -> Libraries -> Add , and add your library file path.
How do I add an external library to my C++ project?
Go to Your Project's Properties by right clicking on project's name and selecting properties. Click on "C/C++ Build". Under Settings->Tool Settings Tab, click on GCC C Linker / Libraries. Then add a library and a search path.