Eclipse Include Paths outside Project Directory - c++

I am having an issue including files outside my project directory. I have a project in eclipse with some header files outside of the project that need to be linked to my project. I have added the path to C/C++ General for the header files and included them in my code. It seems like only one of the files can be seen and the other file I am getting an unresolved inclusion error. Does anyone know how to fix this?

The following is thanks to comments from #user7860670 -- you can see more commentary in eclipse: including a path outside of the project
Short form:
Use system variables.
For include directories relative to your workspace, use something of the form "${workspace_loc}/../my_includes".
For include directories relative to your project, use something of the form "${project_loc}/../my_includes".
Note that in some IDEs, the system variables may be named differently.
See eclipse: including a path outside of the project for more details.

Related

Eclipse C++ in Clearcase vobs: Unresolved inclusion

I would like to get your thoughts on why I am getting an "unresolved inclusion" error for certain .h files included as part of my project.
I actually cloned the project from another existing project, by simply copying, pasting and renaming.
Inside the cloned project, which originally had only a src/ directory, I also created a tst/ directory and did right-click->New->Folder and from the menu, clicked on Advanced >> and selected "Link to alternate location (Linked Folder)" and browsed to the relevant path under /vobs to add the source folder to my project.
Once I did this, the indexer started rebuilding the index, at the end of which I got the above mentioned inclusion errors.
The .h files could be located inside a specific folder path under /vobs; I first tried including this path by right-clicking on the cloned project and choosing Properties->Paths and Symbols->Includes to update the include list with the folder path. This didn't resolve the error.
Subsequently, I tried repeating the above procedure for the newly created tst/ directory from within the project; that didn't resolve the error either.
Not sure what is it that I am missing here.
Any suggestions would be appreciated.
Check first if those files are there, in your view. '/vob' could mean dynamic view, mounted under /vob.
I would rather work with a snashot view, which would download those same files on disk (rather than using the MVFS, Multi-Version FileSystem of a dynamic view).
Then, when you are sure the files are there, and cleartool ls shows them correctly loaded, you can double-check your inclusion paths, as mentioned here
"unresolved inclusion" means the file can't be found.
This means the directory containing it hasn't been specified to CDT or it has been misspelled.
If spelled correctly, normally you would specify the path with Project --> Properties --> C/C++ General --> Preprocessor Include Paths, Macros etc. on the Entries tab as a user entry.
Note that it depends on the type of project.
When you select File --> New -> C/C++ Project you are presented with various options.
The options are for the kind of builder used.
Some, such as Meson, Qt , Arduino and maybe others don't have the option "Preprocessor" option.
My guess is that you are not set in a view when you start Eclipse. This will prevent resolution of the the absolute "/vobs/..." paths. If you start Eclipse from GNOME (or any other windowed environment) the current working directory of Eclipse is likely your home directory. Without a view context, the /vobs/... paths will not contain any files under source control.
You COULD use /view/myview/vobs/myvob/... in the include paths, but that would mean EVERYONE who would use the project would have to either start your view or create and start an identically named one... And that's just the start of that particular can of worms.
You may want to confirm how Eclipse handles relative paths in the include path. Do they start from the current working directory of Eclipse? The project home directory? Somewhere else? That may give you a safe view-independent way to specify your include paths.
I would try setting a view and starting Eclipse from within the subshell spawned by cleartool setview. Then verify whether the includes are accessible.

Eclipse can't find header file, even though include paths are set

This was an issue we've been dealing with for a while now - we're building a C++ project using the Cygwin toolchain, and no matter what we add in the C++ compiler include paths under project settings, Eclipse can't seem to find the necessary header files.
We have done everything the Stackoverflow community has suggested so far;
Made sure include paths were workspace-relative
Tried backslashes and forward slashes
Tried using Cygwin-specific paths (/cygdrive/c instead of C:/)
Checked the compiler output to verify include paths are there
Checked the generated makefiles to make sure they're correct
Rebuilt the index
Deleted the debug folder entirely
restarted Eclipse
Basically nothing short of changing the #include <...> code itself to use a full path (C:/.../file.h) worked. This doesn't work for our needs as we need multiple developers to be able to work on this project, and the files themselves are generated dynamically as a result of some of our build procedures.
So here's a fun little detail about Eclipse we didn't know - specific source files themselves can have their own settings.
If you look at your source files and see the following wrench icon, this means that file has some settings which may be contrary to your project-specific settings.
As a result, our source-specific settings were overriding the include paths, so for those files, none of the headers could be found. The best part is that Eclipse doesn't tell you in any way more explicit than this - the wrench icon does not offer a tool-tip to explain what's going on.
Simply right click on the file > go to Resource Configurations > Reset to Default...
Your header files will be found now, provided that you've written the correct include paths in your project settings.
For reference, we're using Eclipse Kepler - I'm not sure if they fixed this and added more info for users in newer versions.

Include c++ files outside project directory in Eclipse

I have a problem regarding including files that are outside project directory (c). So I have a project in a workspace. There is a folder somewhere on my hard drive, containing a pair of .h and .c files. I would like to use them in several projects, that's why I wanted to place it outside the project.
I tried including this folder, .h file actually in many ways, but the compiler doesn't seem to see the content of it. I can successfully include the file, but the functions inside are not visible.
In the properties of the project -> C/C++ General -> Paths and symbols I have added the folder. What else should I do?
Add the relative path of all those *.c and *.h file.
#include "path_to_header/lib1.h"
#include "path_to_file/file1.c"
I was wondering about the same recently, here is what worked for me:
You have to mark the files as source code. Open project properties dialog and go to source location tab
then you can use Link Folder to select absolute path or you can use the variables to keep it relative to project file or workspace.
For other configurations Add folder was enough since they were already linked.
You also need to add include paths to c or c++ here
There probably already are some default paths so just add the new ones.
It can also be relative using variables.
I had more sub folders so I added them individually and did not use and relative path in #include at all.

Using header files with multiple projects in same solution

I'm using C++ and visual studio 2015. I've created 2 projects in 1 solution. The first project is a static library and the other a DLL. I want to include one header file from the static library to use it in the DLL. I tried specifying the path to the header file with - Project->Properties->C/C++ -> General -> Additional include directories but it doesn't work. When I try to include the header file I get a red underline saying "cannot open source file "SomeHeaderFile.h".
Thanks for the help.
Thanks for the tips but I found out how to make it work. The DLL is in a extra folder. All I had to do was #include "../../TheHeaderFileThatISpentHoursTryingToGet.h". I deleted the reference in the additional include directories path and it still works. I always thought that it made sense for files from different projects in the same solution to be accessible throughout all the projects. Thanks again.

C++ Project dependencies issue Visual studio 2005

I am working on a dataManagement project that periodically deletes files in a specific folder. The solution has three projects of which, one is the application and the other two are static libraries. Now I want to add one more project which is a static library used for logging. The logging static library project has a header file which the application project refers. When I build the solution, I am getting error as the header file is not found. When I added the logging static library project, I also made the application project dependent on it by checking the appropriate bix in the project dependencies.
Can anyone please help me?
It needs an additional include file path to reference the header file directory...
Project->Properties->Config Properties->C/C++->Additional Include Directories
it doesn't auto pick up the header file paths, it just knows how to link to the project.... Its completely undefined where the header file should be. or even if you have a header file, you can forward reference the thing in the other project if you like!
There are two things you need to do to get a statically linked library working in VS. The compiler needs to be able to find the declaration for the symbols that you're referencing and the linker needs to be able to resolve the full definition. When you add the .lib file to the VS project this meets the second obligation. To meet the first you must include the header somewhere in your source hierarchy before the first reference and you must also tell the project where to find the header files. The dependency settings in VS only set the build order - they will not help here. You need to make sure that the folder that your header files are in is added to the "Additional Include Directories" setting in the project properties, or is one of the global include directories in the main VS Options. You must also make sure that the .lib is added to the linker's "Additional Dependencies" setting.