including correct version of header file in eclipse CDT - eclipse-cdt

Hi I am working in a C based project. Here I need to include sched.h in my project. But the problem is inside linux there is multiple sched.h in multiple directory (after installing the linux headers).
Now my question is how to select the proper version of header file which I want to include in my project?

Just #include <sched.h> in your program. It is a standard posix header and
the compiler will find the right one in its default include directories
without any help.

Related

Is there a way to add include directory from C++ code?

I have a project whose vcxproj file is auto generated prior of compilation by using a script during the build process.
this project dependes on a boost library which is installed in a known location on the build machine.
the project header file declares:
#include "boost/foreach.hpp"
which forces me to manually add the path to the boost root folder to the Additional Include Directories field in the vcxproj file.
As the project file is auto-generated it forces me to split the build process into two stages and edit the project file in between.
i have also tried to change the source file and add the full path in the #include statement:
#include "<path to boost root>/boost/foreach.hpp"
but then some boost internal include fails. Which means i can't proceed in this way.
I have read through Set #include directory from C++ code file to find there is no option to add the path from code.
As I'm now on VS2012/C++11 environment i wonder if anything changed in VS2012 / C++11?
Is it still impossible to add an Include directory using a code statement?
You mean dynamically? No, there is no way. The reason is simple:
When you are running your program, it's already compiled, hence the compiler has to know about all the files to include at compile time.
It seems you're using CMake. If that's the case, I recommend you to add the include dirs in the CMake file.
Firstly, doing this:
#include "<path to boost root>/boost/foreach.hpp"
should be strongly discouraged. By doing that, you're making your source code build-able only on your environment - as your project grows, it will be a nightmare to change the path, or for other developers to build it. And, as you discovered, you'll break any headers which are included further down the chain, which are using relative paths.
What kind of script is generating your project? Is it a custom one, or is it a well known build tool such as SCons or CMake? The correct solution is to fix your build script so that it generates the project with the additional include paths correctly.

"Include can't be found", how to fix it?

I am developing using OpenSceneGraph. I installed it from a user-runnable installer.
When I try to compile an application using OpenSceneGraph, I have this error :
Lexical or preprocessor error : Include cannot be found for all <osg/*> includes like <osg/AnimationPath>.
The file is available here /Library/Frameworks/osg.framework/Versions/92/Headers/XXXX So following this solution on how to "add existing frameworks" to the new Xcode, I added osg.framework to the project.
any idea is a welcome.
I am using :
IDE Xcode 4.5
Clang 4.1
OS X Mountain Lion
When compiling you will have to add the include files using the -I option of the compiler and also possibly add library directory using the -L option of the compiler(the options may be a bit different if you are using compiler different from gcc).
I guess both library and the include directories for this product should be subdirectories of the install destination you have chosen. For the include directory of course look for directories containing some kind of header files .h or .hpp and for the libraries look for .lib or .dll doesn't the library documentation mention what includes and libraries you need and where you can find them?
EDIT: you will also have to tell xcode where to search for your includes. I tried googling it and here is one of many results on how to add a directory to the include path of a project.
You will have to located which directory to add to the include path. It seems they set some environment variables in the official documentation for that.
Hope this helps.
You'll need to add /Library/Frameworks to the "Frameworks search path" in the project settings.

Qt4.7 -- "QtCore/QFile: No such file or directory"

I have to set up a Qt development environment for my GUI class. I am working through a tutorial and was instructed to include the <QTCore/QFile> header in my implementation file. However, I cannot build the project because the above header file is not found.
I am not sure what I am missing here -- I installed Qt-Creator and all of the deps from the Debian package manager (currently using Wheezy). The Qt 4.7 documentation in IDE also has a section on the above header files, and yet it can't seem to locate them... odd.
NOTE: Header should have read <QtCore/QFile>.
Just #include <QFile> will be more compatible with Qt5. Also note the capital T you have, it should have been #include <QtCore/QFile> - remember unix/linux file systems are case sensitive.
You looked at the library file, not the include files. Those are different things in C/C++.
As trojanfoe correctly mentioned - you are probably missing the development packages of Qt4.

OpenCV using Eclipse with CDT

I was always using QtCreator for OpenCV but a new project started with a friend needs to be done with eclipse.
I did all things I usually do with QtCreator but I am facing a strange problem. Although I did set the include path (/home/opencv/include) when I try to compile I get errors for missing headers (i.e opencv2/core/core.hpp). In the project explorer under include tag the only headers appear are the ones in the first level of the included directory. This means that cdt does not include headers recursively.
Is this a bug or I have to include every single directory?
I had the same problem yesterday. It searched all around forums but nobody could answer me. Finally I realized that I was doing the include for the whole project and including files for the project is not the same as including files for the source file "source.cpp" (for eclipse, because for VisualStudio it is the same).
So try to rightclick on the .cpp file and include the directories for it. Anyway, if you tell me which version of OpenCV you're using I can tell you more aspects of how to include files in case you keep having troubles.
I hope it helps. When you get errors about missing headers is always related to include. At least it happened to be like this in my case.
If the include path in Eclipse is /home/opencv/include , we assume that inside this directory you have 2 folders: opencv and opencv2.
On your source code you must reference the headers as:
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>
Does that makes sense to you?
Nevertheless, there are several tutorials that can help you configure Eclipse.
I had this problem, too. I think what you need to do is to include the path opencv/build/include, not opencv/include. That's where all the header files are.

Including Libraries C++

How do I properly include libraries in C++? I'm used to doing the standard libraries in C++ and my own .h files.
I'm trying to include wxWidgets or GTK+ in code::blocks and/or netbeans C/C++ plugin. I've included ALL libraries but I constantly get errors such as file not found when it is explicitly in the include!
One error: test1.cpp:1:24: wx/msw/wx.rc: No such file or directory : Yes the .h file library is included; what am I missing?
Do I need to be importing other things as well? Is there a tutorial for this? Obviously my shoddy textbook hasn't prepared me for this.
Firstly, header files are not the same thing as libraries. A header is a C++ text file containing declarations of things, while a library is a container for compiled, binary code.
When you #include a header file, the compiler/IDE needs to know where to find it. There is typically an IDE setting which tells the compiler where to look, or you can do it from the command line, normally using the -I switch. It sounds to me as if you have not set up the path to search for header files on in your IDE.
This means that test.cpp included "wx/msw/wx.rc" but that file cannot be found by your compiler. How to fix this depends on your compiler, but you need to find where wxwidgets is installed and add that to your "Include Paths" so that your compiler knows where to search for it. You can also put a more complete path to it in the include directive.
If the files are present in the same directory as test1.cpp, then probably you use the wrong kind of include. #include <...> is usually used for code that resides outside of the directory that your project is in. #include "..." is for includes inside your project directory (and then if they aren't found there, search in the same places as #include <> would).
It is quite an old question and this didn't really answer it for me.
I reinstalled wxwidgets into the root directory as someone suggested that being in a directory with a space in the name may be part of the problem.
Then I went into project > build options > search directories and removed all entries pointing to original install.
And this fixed the problem