Exclude files from Eclipse Indexing that are included in the build - c++

This question provides good answers to the question of excluding files from indexing that are also excluded from a build. An open question remains: how does one prevent files that are part of the build from populating the code-completion or code-insight functions?
My use-case is a TrueSTUDIO (was System Workbench, was bare Eclipse) project which includes some modules from another project. They are wrapped in safe-to-use stubs and wrappers and should never be called directly. The external modules cannot be edited because they must stay in sync with the other project, so their filenames and other symbols clash confusingly with the current project's. When using code completion to include a header or complete a function name, the filenames and function names of the modules that are not to be used directly appear in the completion lists.
I wish to continue to include the modules in my builds, but not have any of their contents appear in the code-complete/insight features.
I see in Project Properties -> C/C++ General -> Indexer there are options to configure the indexer to use a different build configuration. This is promising, but will probably quickly lead to a indexer that is sorely out of sync with the primary build configuration.
Any advice on a practical method?

The only way I found to exclude files from Eclipse indexing is using the abovementioned Indexer-specific build configuration. In my case, it helped with the annoying problem of indexer freezing on .cu (NVidia CUDA) files.
This is how it works:
Prepare a new (Indexer-specific) build configuration.
Exclude unwanted source files from this configuration using the
Source Location exclude filter.
Let Indexer use this particular build configuration.
Eclipse configuration is a bit tricky with Indexer, so this is a step-by-step guide (as for Eclipse 2021-09):
Preparing a new build configuration:
Project->Build Configurations->Manage->New:
Give it a name, e.g., "4indexer".
Select "Copy settings from" with your preferred configuration. In my case, "Debug" worked just fine.
Excluding unwanted source files:
Project->Properties->Paths and Symbols->Source Location:
Select "4indexer" as the configuration to be managed on the top of the properties window.
Apply an exclusion pattern of your choice. In my case, I added "*.cu" at the end of the "Source Folder Exclusion Patterns" list by clicking Add... button and typing *.cu in the "Add Exclusion Pattern" text field.
Reconfiguring Indexer:
Window->Preferences->C/C++->Indexer:
Allow any Indexer to work with a project-specific build configuration (it was tricky to figure it out): check the "Use the build configuration specified in the project's indexer settings" radio button.
Project->Properties->C/C++ General->Indexer:
Check the "Enable project specific settings".
Select the new build configuration for your project Indexer: check the "Use a fixed build configuration" and select "4indexer" from the drop-down list below.
I also unchecked the "Index source files not included in the build", but I'm not sure if it is necessary.
Sometimes Indexer is trying to reindex a project as you try to reconfigure it, freezing Eclipse. So, I turned it on and off and restarted Eclipse a few times.

Related

Build failed with no stated reason on Segger Embedded Studio after adding custom source files

I'm modifying a simple example project (blinky) from the nRF SDK. I added a header file and a .c file in a new folder inside the project directory then added that path ./lib to the common preprocessor user include directories. I then included the header to main.c.
I can compile the new library on its own but when I build the whole project, I get Build failed error with no stated reason to follow up.
Here is an image of that:
Does anyone here know how to beat this?
I haven't used Segger Studio specifically, but it seems to be the CrossWorks IDE underneath.
In CrossWorks, you have to do the following:
Download & install all relevant libs from inside the IDE, under Tools -> Packages -> Install packages. Grab your specific target MCU as well as any specific boards or libraries you'll be using. In case some needed lib is missing here, you will get very weird errors.
In the project, click on the project name itself in "project explorer". Then in the properties window, check settings (this is a bit different in different versions of CrossWorks, might have to right click and pick properties in older versions). Under "user include directories" you should have something like this:
$(DeviceIncludePath)
$(TargetsDir)/NameOfMCU/Include
$(PackagesDir)/CMSIS_4/CMSIS/Include
$(ProjectDir)/NameOfDirectory
Where "NameOfMCU" is the name of the MCU family used, CMSIS should be there in case you are using any ARM, "NameOfDirectory" is the name of your custom directory (you can add several).
Also, get the debug build working first, before switching to release build.

Change eclipse's default launch configuration for all C/C++ projects

Although there might be questions on SO that appear similar to this one I assure you that none of those have been able to answer mine.
I've been figuring out a way to sort of "automate" (I guess you could say) my eclipse projects. To elaborate, let's say I create a C++ project in eclipse using the project creation dialog. This creates two (default) build configurations for the project (Debug and Release).
The annoyance I have run into is that when launching the project, every time I want to switch build configurations (i.e. Debug or Release) I have to manually change the path to the respective ".exe" in the project's launch config, which is rather cumbersome. (See image below...)
by replacing the "C/C++ Application" field with the following:
${config_name:${project_name}}/${project_name}.exe
The appropriate .exe is launched based on the currently active configuration. This is exactly what I was looking for.
Currently, however, I have to set the launch config this way for every C/C++ project I make since eclipse only generates a run configuration as seen in the image (which is not what I want). My question is, how can I make eclipse automatically produce this launch configuration for every C/C++ project I make?

How to exclude a source file from being build in eclipse (C++)?

I am trying to follow some insane complicated steps in order to be able to create C++ unit-tests for C++ code in eclipse (I am utterly new to eclipse). These steps state to exclude some source files from using in the built - which makes sense to me. However, in my eclipse I do not see any Exclude from built option when right-clicking on the source file. Also, neither this answer nor this answer do work, as I do not see the mentioned options in the list of things when I right-click on the source file.
So how to exclude a source file from a built?
P.S. The Version of eclipse seems to be Luna 4.4.0.
(Or, even better: If anyone knows an easier way to set up eclipse with ANY unit-testing framework in a SIMPLE way,- or knows a different Linux framework to start developing C++ projects with unit-testing right away without trying to set up things in unknown and complicated ways for weeks before starting to actually code something - ideas are VERY VERY welcome...)
I ran into a similar problem.
The C/C++ perspective of Eclipse Luna (4.4) is missing the contextual menu "Exclude from build".
I solve my problem by using the java perpective:
Window -> Open Perspective -> Other... -> Java(default)
Navigate to the file/folder you want to exclude
Right Click -> Resource -> Exclude from build
Then you can switch back to the C/C++ CDT perspective
Project Properties> C/C++ General> Path and Symbols
Tab Source Location
Select the source folder
Click the Edit Filter button
Add the file you want to exclude
I've tried this and it worked on Eclipse:
Right Click the file > Properties ... > Resource > Attributes : Derived.
(Eclipse Indigo)
Hope that helps.
I am using MARS eclipse version.
You have to create a build configuration for each component you are building.
Here is how to do that: multiple_execs
Then for each source file that you do not want included in that build; you right click on that source file and then select Resource Configuration and select Exclude From Build. Then you check the box of the build configuration you created above that you do not want the source a part of.
Here is YouTube video showing this: exclude files from a build

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.

Visual studio 2010 - retain project properties between different build configurations?

I have two projects in my solution. I am currently using the default configuration mode which is 'Debug'. When I want to do a 'Release' build, I switch to Release-mode and then I see all my previous projects properties are set to default, meaning I have to add all properties again manually to this mode.
Is there a convenient way to solve this in VS2010, for example to copy all properties like include paths, preprocessor macros, build macros, etc from 'Debug' to 'Release' mode?
Configuration settings are stored in .vcproj / .vcxproj file. You could open it in some text editor and copy some settings manually, but it wouldn't be convenient. For now you could just open projects properties and copy these settings while switching Debug / Release configuration in the upper left corner of that window.
Next time when you are setting properties that are intended to be the same for all configurations, choose Configuration: All Configurations to avoid troubles.
Property sheets can solve this and a few other property-related issues with ease.
In short, all the properties in a project are just nodes in an XML document, and the property group nodes can have a condition attribute. They're easy to change in any text editor, but a lesser-known feature is the ability to import other XML documents, which can provide settings (for all but a few project-specific ones).
This blog post has a good tutorial on using project sheets, and some more info in this question. You can create them in Visual Studio, edit them (including copying your existing project settings over), then attach them to your project with the property manager (not the property window).
The groups in your property sheet use the same syntax as regular settings, and can be set for all configurations or filtered to only apply on some. They can also be filtered by project name and a few other things, using VS' variable and condition system. For example, I use:
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
<WarningLevel>Level4</WarningLevel>
<TreatWarningAsError>true</TreatWarningAsError>
<Optimization>Disabled</Optimization>
<EnablePREfast>true</EnablePREfast>
<RuntimeLibrary>MultiThreadedDebugDLL</RuntimeLibrary>
</ClCompile>
</ItemDefinitionGroup>
for some of my builds, to apply the same settings to all project (full file here).
One of the most convenient uses is giving the build directory in the file, so all your projects build uniformly into the same directory (make sure to use the project name for the output).
Managing almost all the properties across multiple different builds (debug, release, win32, x64 etc.) can be accomplished with a single collection of settings by using Macros.
Thus, before editing a project settings, make sure you've set Configurations to All Configurations and, Platform: to All Platforms. Now almost all settings can be done in this way, across all the different configurations. Say, you want different configurations and platforms to use different versions of various libraries. Assuming you are using a naming convention that's consistent across all projects, you can then use:
Additional Library Directories: ..\..\foo\bar\lib\$(Platform)_$(Configuration)
You can see what macros will expand to, by hitting the edit button, and then clicking on the Macros>> button.
You could also recreate the new mode you want using the configuration manager and then you can choose from which configuration you want to copy all the settings.