Eclipse CDT Can't Find include file unless full relative path is used - c++

I've been using Eclipse for a while and this has me stymied. I created a library name ITS8410_LIB a few weeks ago and then let it sit while I worked on a supporting library called Reach_Lib. The directory include paths I added back when I first created the project work fine. Today I finished Reach_Lib and went to add its path to ITS8410_Lib. I used the project properties C++ settings to add a workspace path (like I've done many times before). I have only one build configuration. The path is shown in the image (the one highlighted in blue is the specific one I'm talking about in this question).
When I go to include the file in the source neither Eclipse (I see the yellow question mark) nor the compiler (I get a compiler error) can locate the file. If I add the a directory path using the full absolute path syntax the results are the same. I can modify the source code and specify the #include via a full relative path from the current directory, and it is found. Eclipse just won't use the path specified in the project settings. This same Reach_Lib has an associated unit test project and the path is specified with a workspace setting from there and it works fine.
Directory paths that were added before today appear fine. Paths (there are two libs showing this behavior) I add today just seem to be ignored. I took a look at the compiler settings (see image below) and the path specified to the compiler appears to be OK.
Running under Windows7 64 bit (but using a 32 bit version of Eclipse Indigo).
I have tried:
rebuilding indices
Exiting and restarting Eclipse multiple times
workspace and absolute file paths
modifying the order of the include paths
different .h include files in project
Update
I took a look into the .cproject file and while I don't know much about what these files are supposed to look like I think I have a problem. Maybe the question is: How do I tell Eclipse to rebuild the .cproject file? I appear to have two similar sections and Eclipse is getting confused. I can see different version numbers tagged as suffixes. It appears to me that the visual editors are letting me modify one section but the IDE and compiler only care about the other section. Here's the relevant portions
...
<folderInfo id="nbeclipse.toolchain.nbl.rel.396284009." name="/" resourcePath="">
<toolChain id="nbeclipse.toolchain.nbl.rel.tc.1465290409" name="NetBurner Device Library" superClass="nbeclipse.toolchain.nbl.rel.tc">
<targetPlatform id="nbeclipse.toolchain.nbl.rel.tc.targetPlatform.283367649" isAbstract="false" name="NetBurner Module Library" superClass="nbeclipse.toolchain.nbl.rel.tc.targetPlatform"/>
<builder buildPath="${workspace_loc:/ITS8410_Lib/Release}" id="nbeclipse.toolchain.nbl.rel.tc.builder.2064025940" keepEnvironmentInBuildfile="false" managedBuildOn="true" name="Release ELF builder (MINGW)" superClass="nbeclipse.toolchain.nbl.rel.tc.builder"/>
<tool id="nbeclipse.toolchain.nbl.rel.tc.gcc.278195048" name="GNU C Compiler" superClass="nbeclipse.toolchain.nbl.rel.tc.gcc">
<inputType id="nbeclipse.toolchain.nbl.rel.tc.gcc.input.1060035859" name="GNU C Input" superClass="nbeclipse.toolchain.nbl.rel.tc.gcc.input"/>
</tool>
<tool id="nbeclipse.toolchain.nbl.rel.tc.gpp.767008127" name="GNU C++ Compiler" superClass="nbeclipse.toolchain.nbl.rel.tc.gpp">
<option id="nbeclipse.toolchain.super.gcc.directories.includepaths.1666029541" name="Include paths (-I)" superClass="nbeclipse.toolchain.super.gcc.directories.includepaths" valueType="includePath">
**inside here is an option list with all my include paths**
...
</folderInfo>
Then right after the folderInfo close tag another folderInfo section starts
<folderInfo id="nbeclipse.toolchain.nbl.rel.396284009.2022231003" name="/" resourcePath="src">
<toolChain id="nbeclipse.toolchain.nbl.rel.tc.1982112905" name="NetBurner Device Library" superClass="nbeclipse.toolchain.nbl.rel.tc" unusedChildren="">
<targetPlatform id="nbeclipse.toolchain.nbl.rel.tc.targetPlatform" isAbstract="false" name="NetBurner Module Library" superClass="nbeclipse.toolchain.nbl.rel.tc.targetPlatform"/>
<tool id="nbeclipse.toolchain.nbl.rel.tc.gcc.1671008421" name="GNU C Compiler" superClass="nbeclipse.toolchain.nbl.rel.tc.gcc.278195048">
<inputType id="nbeclipse.toolchain.nbl.rel.tc.gcc.input.436341699" name="GNU C Input" superClass="nbeclipse.toolchain.nbl.rel.tc.gcc.input"/>
</tool>
<tool id="nbeclipse.toolchain.nbl.rel.tc.gpp.498310867" name="GNU C++ Compiler" superClass="nbeclipse.toolchain.nbl.rel.tc.gpp.767008127">
**the newly added paths don't show up here, if I add them manually things start working**

The key to the answer was posted by dbrank0 but he didn't promote it to an answer so I just upvoted the comment. Something went wrong in the .cproject file and editing it manually fixed the problem.

Try to replace relative workspace path to real path (add same include as filesystem) in include directories project settings.

full absolute path is okay at any time.
when use the relative directory you should be careful.
in eclipse the current directory is not the same as run directory.
string strRunDir, strCurDir;
strRunDir = AfxGetApp()->m_pszExeName;
strCurDir = GetCurrentDirectory(...);
and strRunDir != strCurDir;
when you want to use the relative directory, you should reference to the runDir;

Related

C++ Windows Driver MSB3030 could not copy the file '' because it was not found

VS2017, SDK/WDK, C++ project
we have a c++ solution (driver) that is shared across developers via Team Foundation Services - visualstudio.com (now called azure devops?).
When I perform a get latest source code, and want to rebuild the solution I get two MSB3030 errors:
"Could not copy the file "C:\path of my colleague his file" because it was not found."
I found it strange that I saw on one of the two errors a path of my colleague his pc. He works on C:\ I'm working on E:\
Unloading the project, I saw he path being set here:
<ItemGroup>
<FilesToPackage Include="C:\path of my colleague\foo.xml" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<PackageRelativeDirectory>
</PackageRelativeDirectory>
</FilesToPackage>
We cannot get this solution to build because of the MSB3030. First we have to clean the specific projects individually, rebuild it, then build another project etc.. a few steps to perform manually in the correct order , trial and error, drinking coffee, throwing bananas to the pc and praying that a monkey outputs the code correctly.
Has anyone seen somehting similar regarding MSB3030 errors?
On my pc I see the path of my colleague, but he doesn't see my path (strange!).
C:\Program Files (x86)\Windows
Kits\10\build\WindowsDriver.common.targets(1699,5): error MSB3030:
Could not copy the file 'C:...' because it was not found.
I've set the Any CPU to x64 because it doesn't make any sense for c++.
C++ Windows Driver MSB3030 could not copy the file '' because it was not found
The reason for this issue is that the path of the ItemGroup is an absolute path in the project file:
<ItemGroup>
<FilesToPackage Include="C:\path of my colleague\foo.xml" ...>
...
</FilesToPackage>
</ItemGroup>
Regardless of whether your colleague has added this file to source control, when you pull the code from the TFS server to your local and put the code in a different local folder, the absolute path will bring you a lot of trouble, you need to manually check the code on the TFS server for this file and you need to modify the absolute path of this file in your project. But this problem will reappear after your colleague updates after you submit your code. Because an absolute path cannot be assigned to two different paths C:\ and E:\.
To resolve this issue, you need to change the absolute path to a relative path in the source code. Generally, we prefer to add this file to the Solution/Project folder, then use the MSBuild Macros $(SolutionDir)/$(ProjectDir) to specify it.
Check Common macros for build commands and properties for some more details.
Hope this helps.

IAR C Preprocessor include directories

I've been asked to make a small mod to some software that was written back in the mid naughties on IAR Embedded Workbench v3.3
I have had the original source files copied from an old machine to one I have been given for the task.
For the moment I am simply trying to get the software compiling. It took me a while to realise, or at least I thought I'd realised, that the reason it couldn't open various header files was that, incredibly, all the include paths were absolute, not relative.
So, I changed all the paths to be $PROJ_DIR$ relative, but then started to get different files that couldn't be opened. Then realised that the machine they gave me just happened to have a very similar directory structure to the original machine used and, amazingly, had quite a few of the same files in the directory structure of this machine I'm using as was on the machine used to compile the code originally.
I then thought, OK, I'll just check I have got my relative paths correct by choosing one of the header files it was complaining about not finding and putting, in the Preprocessor tab, an absolute path to the directory on this machine I'm using that contained the header file it wanted. However, that still wouldn't find the header file!
Finally, I put an absolute path in the c file to point to the desired header file.
#include "C:\absolute__Path\stdtyp.h"
And it compiled.
To confirm:
Putting C:\absolute__Path
in the Project | Options | C/C++ compiler | Preprocessor tab will not work if I just have:
#include "stdtyp.h"
in the c file.
I have used IAR in the past - not that much - but I have used it and I was sure that's where you set your include directories. So, am I wrong, or can there be something else that is overriding that path in the Preprocessor tab as described above?
Edit: I'm not wrong, after having slept on it, I decided to create a new project with random directories, subdirectories and header files. Sure enough, if I set and remove $PROJ_DIR$ referenced paths in the preprocessor tab, the new project compiles, then doesn't. So, there must be something, presumably in the ewp file that is borking it.
It turns out you can override the paths on an individual file by file basis. So, the rogue files had the paths overridden and had absolute paths.
Right click on the file in EW and select Options.
That then for most file shows a load of greyed out boxes. What I'd failed to do was thoroughly check all files. The few I'd randomly checked were greyed out, but some files had their properties overridden here with different (and absolute) paths put there.
At least now the project can be easily copied between machines having used relative paths.

Xcode folders and groups confusion

I'm using Xcode (with C++) and my project layout (in the file system, not in Xcode) looks like this:
SubfolderA
-file_A_1, file_A_2
SubfolderB
-file_B_1, file_B_2
Right now I've set up this structure in Xcode via groups. And so, when I want to include file_A_2 in file_B_1, I write #include "file_A_2" in file_B_1.
Is there some way to make an inclusion look like #include "/SubfolderA/file_A_2", so that I can easily see to what directory/subfolder an included file belongs?
One way to see what's going on is to look at the Build Log and expand the line for compiling sourcefile.m. Look at the -I options being passed to the compiler.
If it's not to your liking you can add the source tree in the Build Settings > Header Search Paths to include $(ProjectDir)/srcroot and make it recursive, which saves you from adding each sub-folder individually.
In my experience this has never been necessary, however, as far as I can remember.
As far as the Xcode folders are concerned, if the top-level source folder is added then all sub-folders are automatically added when you add them to the filesystem, saving the hassle of keeping them in sync. You might need to add the top-level folder under the Source Files group for this to work, however.
Surprisingly, in Xcode's Build Settings I've added to User Header Search Paths non-recursive path to my project. This solved my problem.
I ended up here when I was having an issue with XCode while trying to include a header in a group by doing
#include "MyGroup/MyHeader.h"
Turns out the project structure and the file system weren't in sync, so I just had to remove my group from the project, put it in the correct place in Finder, then drag and drop it back into the project in the correct place and it worked for me.
I'm not sure if this is necessary or not, but I also have already set up my app's working directory because I am doing some game programming and need to be able to load in .png and make textures.

Eclipse can't find header filers even though include paths have been set

When creating a new C project in a particular Eclipse environment which uses GCC, I run into a peculiar linker problem:
Fatal error: my_header.h: No such file or directory.
I get this problem since "my_header.h" resides in a sub folder. After investigation, I found out that you need to include sub folders in the GCC include path (option -I). How this is done seems to vary between different Eclipse implementations, but it should be something like
Project -> Properties -> C/C++ Build -> Settings -> Compiler -> Includes
Where "compiler" may have a different name in different implementations, and "includes" may be called "input" or similar.
There should be an option to add the include path (option -I) where you can set the path relative to the specific project, by clicking an "Add" icon followed by Workspace button, then select the directory. Eclipse then generates a path, which should look something like
"${workspace_loc:/${ProjName}/app}"
Do this for all sub folders in the project (and their sub folders).
But despite doing the above for the relevant folder, I still get the "no such file or directory" error. What could be the problem?
(I'm posting this Q&A style since I want to share the solution of this problem with others)
The reason for this error is that there is no sanity check for the gcc include path. Despite giving a relative path to Eclipse as described, Eclipse will still pass an absolute path to gcc -I.
Suppose you have your project located at a path like:
C:\åäö\workspace\project
and the sub folder located at
C:\åäö\workspace\project\std
where "åäö" is any string containing any non-standard ASCII letters. In this example I used Swedish, but you'll encounter such non-standard letters in most languages (French, German, Spanish etc).
The problem is that Eclipse passes the full path, rather than the relative one to GCC, and then there is some sort of symbol table mishap. So rather than getting the expected
-I"C:\åäö\workspace\project\std"
you might get random garbage letters such as:
-I"C:\#!#\workspace\project\std"
The path doesn't make sense and the include path is not sanity checked, so you get no diagnostic telling you about this, unless you read the console output in detail. Instead, Eclipse silently pretends that it has added your include path to the list of paths it should check, even though it has not.
The only solution seems to be avoiding placing your projects below paths that contain non-ASCII letters. It would seem that this is a bug in several implementations of Eclipse that use GCC.

XCode 4 Relative #include paths in search?

I'm trying to port over a project I initially wrote in Windows to OS X and am having some difficulty with the header search paths.
I've used user search paths to include by source folder "project/src/core/"
Under core, I have, for example:
"projects/src/core/sys/sys_sdl.h"
which tries to include
"projects/src/core/render/opengl_render.h"
with the directive:
#include "render/opengl_render.h"
I've tried tons of different options, but I can't get seem to get Xcode to find the file unless I change it to "../render/opengl_render.h"
Is there something I'm missing here in the settings to get it to recognize relative paths to the header search paths?
Did you try setting the User Header Search Path to $SRCROOT/..? $SRCROOT is the directory that contains the target's source files, so $SRCROOT/.. should be the directory above that, which I think is what you want.
A related question (How do I print a list of "Build Settings" in Xcode project?) shows a useful command that makes it easy to see all the build settings and the variables they modify:
$ xcodebuild -project myProj.xcodeproj -target "myTarg" -showBuildSettings