I have been using the Indigo release for some time. I keep having a reoccuring problem with enumerations defined in include files not working. The IDE reports the symbole can't be resolved but if I copy it to the file it complains about a conflict.
This shows that it does indeed resolve it but doesn't like it for some reason.
I really hate having to code the same enumeration in many different files. Isn't that what includes are all about?
Have a look at this answer: https://stackoverflow.com/a/774914/132847
After that, you should:
check your CDT's C++ Indexer configuration. (I don't know what is the size of your project, but it might help to increase your cache's size.)
Add your headers' directories to the include path in the eclipse's project configuration (if they are not part of your project) this way:
Select “Project > Properties” from the menu. A dialog comes up. In the
tree on the left open: “C/C++ General > Paths and Symbols”.
Add your header files' path to the include path
Good luck,
Tal
Related
When I build my c++ solution in Visual Studio it complains that the xxxxx.pch file is missing. Is there a setting I am missing to get the pre-compiled headers back?
here is the exact error for completeness:
Error 1 fatal error C1083: Cannot open precompiled header file: 'Debug\xxxxx.pch': No such file or directory
NOTE: Later versions of the IDE may use "pch" rather than "stdafx" in the default names for related files. It may be necessary to substitute pch for stdafx in the instructions below. I apologize. It's not my fault.
Right-click on your project in the Solution Explorer.
Click Properties at the bottom of the drop-down menu.
At the top left of the Properties Pages,
select All Configurations from the drop-down menu.
Open the C/C++ tree and select Precompiled Headers
Precompiled Header: Select Use (/Yu)
Fill in the Precompiled Header File field. Standard is stdafx.h
Click Okay
If you do not have stdafx.h in your Header Files put it there. Edit
it to #include all the headers you want precompiled.
Put a file named stdafx.cpp into your project. Put #include "stdafx.h"
at the top of it, and nothing else.
Right-click on stdafx.cpp in Solution Explorer. Select Properties
and All configurations again as in step 4 ...
... but this time select Precompiled Header Create (/Yc). This will only
bind to the one file stdafx.cpp.
Put #include "stdafx.h" at the very top of all your source files.
Lucky 13. Cross your fingers and hit Build.
Precompiled Header (pch) use is a two-step process.
In step one, you compile a stub file (In VS200x it's usually called stdafx.cpp. Newer versions use pch.cpp.). This stub file indirectly includes only the headers you want precompiled. Typically, one small header (usually stdafx.h or pch.hpp) lists standard headers such as <iostream> and <string>, and this is then included in the stub file. Compiling this creates the .pch file.
In step 2, your actual source code includes the same small header from step 1 as the first header. The compiler, when it encounters this special header, reads the corresponding .pch file instead. That means it doesn't have to (re)compile those standard headers every time.
In your case, it seems step 1 fails. Is the stub file still present? In your case, that would probably be xxxxx.cpp. It must be a file that's compiled with /Yc:xxxxx.pch, since that's the compiler flag to indicate it's step 1 of the PCH process. If xxxxx.cpp is present, and is such a stub file, then it's probably missing its /Yc: compiler option.
Fix:
Make sure you have xxxxx.cpp in your project
Compile xxxxx.cpp with /Yc flag (Create Precompiled Header)
(right click on xxxxx.cpp -> properties -> Precompiled Headers -> create)
Compile all other files with /Yu flag (Use Precompiled Header)
(right click on project -> properties -> Precompiled Headers -> use)
Right click to the project and select the property menu item
goto C/C++ -> Precompiled Headers
Select Not Using Precompiled Headers
Yes it can be eliminated with the /Yc options like others have pointed out but most likely you wouldn't need to touch it to fix it. Why are you getting this error in the first place without changing any settings? You might have 'cleaned' the project and than try to compile a single cpp file. You would get this error in that case because the precompiler header is now missing. Just build the whole project (even if unsuccessful) and than build any single cpp file and you won't get this error.
In case this is happening to you on a server build (AppCenter) and yo uaer using CocoaPods ensure that your Podfile is checked in.
AppCenter only runs the "pod install" command if it finds a Pofile and it DOES NOT find the PODS folder on the files.
I had the folder checked-in, but because git automatically ignores .pch files (check you .gitignore to veryfy this), my .pch weren'nt being checked in.
I sorted my issue by forcing the .pch files to check it, but Deleting the PODS folder should work too, since Appcenter will run the pod install command in that case.
Hoppefully this helps somebody.
VS screwed (mine is 2019 ;( ).
Go ahead and choose "not using precompiled headers" as other guys are pointing out then open the project file (vcxproj) with any text editor, and delete the outlined two entries in two places. Enjoy cleaning up the mess!
As a matter of fact, the 'pch.h' entry in the vcxproj file you see it below, you will ever find it in VS properties' interfaces.
Try Build > Clean Solution, then Build > Build Solution. This works for me.
I know this topic is very old, but I was dealing with this in VS2015 recently and what helped was to deleted the build folders and re-build it. This may have happen due to trying to close the program or a program halting/freezing VS while building.
I was searching for the iOS PCH file having the same problem, if you got here like me too, the solution that I've found is by clearing derived data; Close Simulator(s), go to xCode prefs -> locations -> go to the derived data file path, close xCode, delete the files in the derived data folder, re launch and cheers :)
I managed to create this problem for myself because I wanted to use a pch.h and pch.cpp file from different directories. So, I deleted the two files from my project and then added them as existing files from somewhere else. Big mistake as precompiled header files can no longer be found.
There is no way that I can find to fix the problem from the Visual Studio 2019 UI. You must edit the project file and make sure the following look like this:
<ClCompile Include="pch.cpp">
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Create</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">Create</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Create</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|x64'">Create</PrecompiledHeader>
</ClCompile>
I had same issue, and I managed to solve it like this:
ERROR :
fatal error C1083: Cannot open precompiled header file : "Debug\myProj.pch". No such file or directory
first one is when I had an error,
and changed it like a second picture
make (/Yx)
myProj.h
In my case, it was necessary to select Create (/Yu), instead of the standard Use (/Yu)
to
If everything is right, but this mistake is present, it need check next section in ****.vcxproj file:
<ClCompile Include="stdafx.cpp">
<PrecompiledHeader Condition=
In my case it there was an incorrect name of a configuration: only first word.
I have a C++ project built of several shared libraries. Each library source code is placed under its subtree of directories. The main CMakeList file contains a list of add_subdirectory(<dirname>) directives. CMakeList files in every subdirectory contain definitions like the following:
set (SOURCE_FILES
util/src/Connector.cpp
pub/util/Connector.h
)
add_library(channels SHARED $( SOURCE_FILES))
SET_TARGET_PROPERTIES(channels PROPERTIES LINKER_LANGUAGE CXX)
where channels is the subdirectory name.
Although the search path for include files is set correctly and compilation works, KDevelop does not see the Connector.h header file and, therefore, its parsing and code/class browser do not work.
I know that .kdev_include_paths file in every directory might solve the problem. Unfortunately, this approach may not be used due to some additional constraints in our development environment.
Is there any other way to solve this issue?
I use Intel C/C++ compiler on RHEL 7.1 with KDevelop 5.0.4 running from AppImage.
I found and solved a problem which presented similarly - header files not seen and code/class browser failing. The cause turned out to be an error in my code. For the benefit of others who may write a similar bug and arrive at this page, here is what I did wrong:
I had a header only class in a file 'myClass.hpp' and an empty implementation 'myClass.cpp'. My CmakeLists.txt cited the implementation, but my implementation did not contain #include "myClass.hpp". The effect in Kdevelop-5.1.0 was that the header file was not parsed as part of the program - hence its includes were not read, and much of the code failed semantic analysis.
On KDevelop 5 this solved my issue:
Go to menu "Project" -> "Open Configuration..."
In the window which now opens, go to "Cppcheck" on it's left side and then to "Include Directories" on it's right side
check the "Use 'system' include dirs" option:
Try adding
include_directories(${SOURCE_FILES})
It appears I experienced the same problem.
Symptoms:
-- Kdevelop 5.1.2 could not find some #includes; they were underlined in source files.
-- There was no problem building the project
Cause:
-- Both symbolic links and the original *.h files were in the paths specified in
include_directories( ) in CMakeLists.txt. Symbolic link removal fixed the problem.
Kdevelop is probably right to be confused about multiple *.h files with the same name.
Maybe some future Kdevelop release will be able to recognize that it is dealing with only one target.
I want to include a header file. I am working in a C++ environment, (C++11, Windows OS, Netbeans 7.3.1 IDE, Cygwin_4.x tool collection). I do not know how I setup the environment/IDE (I did it 6 months ago). I do not understand the fundamentals of the C++ build process or Cygwin related issues either, so I might have to fill in the gaps with some other references/documentation (on what specifically, I'm not sure).
My ultimate objective is to be able to include header files using a syntax that does not require the full file path. I want to write something terse, like:
#include "src\stuff\blah.h" //or even better: #include "blah.h"
The only way I can get my program to compile at all is by using the full file path, like this:
#include "C:\NetBeansProjects\Project1\src\stuff\blah.h"
And, I can only compile once using the full path. If I try to rebuild, it will bomb with the *** multiple target patterns. Stop. error. There are workarounds for this error; those being either 1) deleting the build and dist folders between each rebuild (yikes?), or 2) following this 16 step setup process.
I do not want to follow either of those workarounds because they do not appear to deliver what I want. How can I setup my environment to achieve what I want...of being able to include header files without using full paths?
Thanks to DanielKO for this answer.
In my case, I was able to include with the syntax:
#include "../stuff/blah.h"
I did not have to configure anything under the "Code Assistance" section for the C++ compiler.
All of my code is under "src" as the parent directory in my NetBeans project. It seems that the full path of the file is not required, and the only directory that must be referenced is the lowest level subdirectory (in my case, "stuff").
In NetBeans I've added the path to the list of libraries:
Go to Properties->Select C++->Select 'include libraries'->'Add'
Now: Add the path of the project folder with option "absolute"
Go to Properties->Select C++->Select 'Additional library directories'->'Add'
Now: Add the path of the project folder with option "absolute"
It's very obscure to me why the project doesn't recognize "own" header files.
#include "enum.h"
Using visual studio's the code above is what I had typed, in fact once I typed the double quotes it automatically provided me a list of all available header files in the directory the file I was working on was located.
It is also included under "Header Files", it certainly sees the file there, but intellisense isn't detecting it; additionally it seems to also be causing some other syntax errors further along the line, so I want to rule this out as an issue.
I read there was something about typing the path in the properties > VC++ Directories > Include Directories but I have no idea what the proper syntax is to make sure its properly included. Do I just need to link the route folder for my project or each individual header file?
It didn't use to cause this problem but at random now it does.
Edit: At some point after some unreproducible fiddling some of them work, though others don't for no explainable reason. Sometimes it will "work" and Intellisense won't complain, but after compiling, bam, error pops up again.
Yes, you need to make sure the path of all your own include files are present in Properties > VC++ Directories > Include Directories, (you don't need to worry about the standard library include files as compiler will already be able to find those). The directories in here should be separated by a ;. If you don't want to type the directory in manually you can click the down arrow to the right of Include Directories > Edit... > Add Directory Icon, then browse to the directory of your include file and add it like that.
Something to try:
Right click the #include and click Open Document.
If it can open the file then the IntelliSense is corrupted, and you will probably need to regenerate the IntelliSense file.
If the file won't open, it will give you a message with the current folder paths that are searched, so you can copy your files there or search why is that your path wasn't searched
Check some other answers:
link1
link2
link3
I've just started using Eclipse Indigo (coming from Galileo) and I'm getting little red bugs in the gutter for every use of size_t.
The code compiles without issue but I suspect I have to explicitly add a path to the include directories. I already have the usual suspects in there. I am cross compiling for a ColdFire processor using the Gnu tool chain so in addition to the standard include from mfg of the chip I have the includes under m68k-elf
\include
\include\c++\4.2.1
\include\c++\4.2.1\include
\include\c++\4.2.1\m68k-elf
Update
I noticed that the only place stddef.h exists for this toolchain is in a lib directory
gcc-m68k\lib\gcc\m68k-elf\4.2.1\include
I added that path, the parent path and \include-fixed from the parent but the problem still exists.
Note on testing
When testing what works and what doesn't I noticed a couple of things
Code analysis does not get re-triggered when modifying Code Analysis preference settings, I still need to make an editor change (simply adding a space works)
Turning off the Code analysis setting for Symbol is not resolved will not make the error go away.
Turning off all Syntax and Semantic Errors, triggering the analysis, going back in and turning them all back on and then turning off Symbol is not resolved keeps the error from reappearing.
Check your indexer settings under Preferences -> C/C++ -> Indexer.
There is a field there called "Filed to index up-front". Its contents should be:
cstdarg, stdarg.h, stddef.h, sys/resource.h, ctime, sys/types.h, signal.h, cstdio
If there is something else in there, try replacing it with the above, then rebuild the index, and see if that fixes the problem.
(In particular, if what you have in that field is stdarg.h, stddef.h, sys/types.h, then I have a pretty good guess as to what went wrong. Back in Eclipse Ganymede, the value of this field was stdarg.h, stddef.h, sys/types.h. In newer versions (Galileo and Indigo), it was changed to the above. However, since this field is part of "preferences", if you exported your Ganymede preferences and imported them into Galileo/Indigo, this field was overwritten with the old Ganymede value. I was burned by this a while ago.)
To make sure to get size_t you should #include the header <cstddef>; then, it would be std::size_t, unless you also put a using namespace std or a using std::size_t.
If your toolchain can compile the code with only its default include paths and symbols, just setting Eclipse to use them should be enough. Go to C/C++ Build -> Discovery Options in the project properties, and for each language, change the Compiler invocation command from the native compiler (e.g. g++) to your cross compiler (e.g. C:\nburn\gcc-m68k\bin\g++ perhaps?). Then on the next build, the auto-discovery will run and update the so-called "built-in" paths and symbols that show up in the project's C/C++ General -> Paths and Symbols to whatever your compiler reported, and you can re-index again to make sure any warnings for the old "built-ins" are gone.
After hitting this problem and a search revealing two stack overflow questions hitting the same problem, I figured I would submit how I fixed it after it annoyed me enough to actually investigate.
I'm running Fedora and annoyingly, it has a stddef.h file in /usr/include/linux.... which is actually empty. So even though I had the compiler's stddef.h in the include path, the indexer was actually parsing this other empty file. So what needed done was:
Prefix your paths and symbols list with the compiler specific include path (in my case it was /usr/lib/gcc/x86_64-redhat-linux/4.7.2/include/) to avoid the other empty stddef.h from being parsed.
I actually had the same problem. The issue seemed to be the same like the one described in the post of fquinner, the stddef.h located in /usr/include/linux/stddef.h was empty as well. Strangely enough, the correct stddef.h was found by eclipse and even could be openened without any issues.
If you just need to fix the indexing by eclipse like me (for example when building with another build tool anyway), this indexing issue can be worked around by defining __SIZE_TYPE__ to the expected type, e.g. long unsigned int under C/C++ General -> Paths and Symbols.